how to integrate my iphone app with twitter api? - iphone

I need to tweet and also retrieve tweets.is any api available for this, any sample application or code .
.thank you in advance

This is now built in to iOS5. Take a look at the Twitter Framework Reference

if you're planning to support iOS version before 5.0, have a look on the MGTwitterEngine, http://mattgemmell.com/2008/02/22/mgtwitterengine-twitter-from-cocoa/

see this link may be it help to u
https://github.com/bengottlieb/Twitter-OAuth-iPhone/
here some code
- (void)viewDidAppear: (BOOL)animated {
// Twitter Initialization / Login Code Goes Here
if(!_engine){
_engine = [[SA_OAuthTwitterEngine alloc] initOAuthWithDelegate:self];
_engine.consumerKey = kOAuthConsumerKey;
_engine.consumerSecret = kOAuthConsumerSecret;
}
}
if([_engine isAuthorized])
{
[_engine sendUpdate:#"your posting data"];
}
import authtwitterengine

I agree with Benjie, you should try and use the Twitter API that's built into iOS 5. Here's how: http://www.peterfriese.de/the-accounts-and-twitter-framework-on-ios-5/

Related

Facebook SDK FBLoginView getting EXC_BAD_ACCESS

I'm following the HelloFacebookSample project bundled with the Facebook SDK 3.5. I've virtually copied and pasted everything into my own app, even the stuff from the AppDelegate, yet for some reason clicking the Login button freezes my app. Just for the record, everything authenticates correctly when connecting to the integrated framework in iOS 6, which is done through the FB SDK anyway. It's only when I try to log in using the web, i.e. hit the FBLoginView website opens, get authenticated, return to app. Here is the code in the samepl project, and I'll compare it to mine:
FBLoginView *loginview = [[FBLoginView alloc] init];
loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = self;
[self.view addSubview:loginview];
[loginview sizeToFit];
Mine is a little different:
loginview = [[FBLoginView alloc] init];
loginview.delegate = self;
[self.facebookCell addSubview:loginview];
[loginview sizeToFit];
As for the delegate methods, I've implemented them all verbatim. Why does the app crash? There is no valid reason for a crash when all the code is pretty much identical between my app and the sample app. The debugger doesn't help much even with Zombie Objects on. The actual error is: Thread 1: EXC_BAD_ACCESS (code=2, address=somethingoranother) Anyone got any ideas as to why this is happening?
Regards,
Mike
UPDATE: It appears that the crash happens because something is recurring infinitely on a loop. Seems like over 100,000 processes were put on the main thread by the FB SDK! How?!
UPDATE 2: I'm beginning to think the error is here, even though I copied this straight from the sample AppDelegate.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
return [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
fallbackHandler:^(FBAppCall *call) {
NSLog(#"In fallback handler");
}];
}
Does this help at all?
I'm having whats seems to be the exact problem, but I have my application sandbox mode already disabled. This app has been working perfectly before, but I just upgraded the SDK and now this happens.
If I have a facebook account configured in iOs, it will work ok, but if not, It will crash.
One thing worth mentioning is if I remove the url scheme, so the app can't go to the web browser or the facebook app, It will user a web view to log in and this works too
EDIT: As far as I'm able to tell, my problem relies in not having access to my application settings in facebook.
The facebook SDK does an [FBUtility fetchAppSettings:callback:] call, more specifically, it does an
https://graph.facebook.com/267496536695242?fields=supports_attribution,supports_implicit_sdk_logging,suppress_native_ios_gdp,name,
which in the case of my app fails with:
{
"error": {
"message": "Unsupported get request.",
"type": "GraphMethodException",
"code": 100
}
}
In comparision, any of the examples apps, for example this one, SessionLoginSample
https://graph.facebook.com/380615018626574?fields=supports_attribution,supports_implicit_sdk_logging,suppress_native_ios_gdp,name
returns correctly this:
{
"supports_attribution": true,
"supports_implicit_sdk_logging": true,
"suppress_native_ios_gdp": 0,
"name": "SessionLoginSample",
"id": "380615018626574"
}
Because the SDK expects something it keeps making the same request and gets stuck in a loop until the simulator crashes.
To confirm this, I've manually inserted the expected parameters in the callback, modifyng the facebook sdk, and now everything work perfectly.
It's worth mentioning that I upgraded the SDK from 2.0 which was deprecated, and there was a few parameters in the settings page that were outdated (no client token set, authorization as native/Desktop instead Web, without having the app secret key in the app) but I've already set them alright..
EDIT 2:
This is the method from Facebook SDK (in FBUtility.m) that I've modified. I only added the "bad stuff" if clause.
+ (void)fetchAppSettings:(NSString *)appID
callback:(void (^)(FBFetchedAppSettings *, NSError *))callback {
if (!g_fetchedAppSettingsError && !g_fetchedAppSettings) {
NSString *pingPath = [NSString stringWithFormat:#"%#?fields=supports_attribution,supports_implicit_sdk_logging,suppress_native_ios_gdp,name", appID, nil];
FBRequest *pingRequest = [[[FBRequest alloc] initWithSession:nil graphPath:pingPath] autorelease];
if ([pingRequest startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// Bad stuff
if (error) {
error = nil;
result = [NSDictionary dictionaryWithObjectsAndKeys:#"true", #"supports_attribution",
#"true", #"supports_implicit_sdk_logging",
#"0", #"suppress_native_ios_gdp",
#"Your_App_Display_Name", #"name", nil];
}
if (error) {
g_fetchedAppSettingsError = error;
[g_fetchedAppSettingsError retain];
} else {
g_fetchedAppSettings = [[[FBFetchedAppSettings alloc] init] retain];
if ([result respondsToSelector:#selector(objectForKey:)]) {
g_fetchedAppSettings.serverAppName = [result objectForKey:#"name"];
g_fetchedAppSettings.supportsAttribution = [[result objectForKey:#"supports_attribution"] boolValue];
g_fetchedAppSettings.supportsImplicitSdkLogging = [[result objectForKey:#"supports_implicit_sdk_logging"] boolValue];
g_fetchedAppSettings.suppressNativeGdp = [[result objectForKey:#"suppress_native_ios_gdp"] boolValue];
}
}
[FBUtility callTheFetchAppSettingsCallback:callback];
}
]
);
} else {
[FBUtility callTheFetchAppSettingsCallback:callback];
}
}
Someone found the answer on another thread. In the Facebook Developer centre, the app was set to Sandboxing mode which is what caused this error. Seems it wasn't a problem with the code after all.
Facebook has fixed a server error that was causing this for a lot of developers. However, the server fix only makes the infinite loop problem less likely to happen. It is still there. I created a new bug to track the infinite loop problem.
https://developers.facebook.com/bugs/446010282155033
It's a memory access error, because the loginView is in a __block space.
Just move your controller ( the loginView delegate ) in this zone and it should work.
FBLoginView *loginview = [[FBLoginView alloc] init];
static id staticDelegateInstance = self;
loginview.frame = CGRectOffset(loginview.frame, 5, 5);
loginview.delegate = staticDelegateInstance;
[self.view addSubview:loginview];
[loginview sizeToFit];

Is automated sharing possible for Twitter in the background on iOS?

I wanted to share a Twitter feed on the Twitter wall which contains an image and some text. I want support from iOS 4.3 to iOS 6.0.1. Is sharing possible in the background without a send/share button? How do I implement it?
The API call that you need to send is:
https://dev.twitter.com/docs/api/1.1/post/statuses/update_with_media
Before making that call, of course, you will need to authenticate with Twitter via xAuth/OAuth. Unless you get special permission from Twitter to do otherwise, it looks like you will need to use OAuth,
https://dev.twitter.com/docs/oauth/xauth
To background the request, it will likely make sense to use Grand Central Dispatch --that is unless you have a lot of different Twitter requests to send. In that case, I would instead opt for an NSOperationQueue where maxConcurrentOperationCount = 1. See the following:
http://www.fieryrobot.com/blog/2010/06/27/a-simple-job-queue-with-grand-central-dispatch/
http://www.raywenderlich.com/19788/how-to-use-nsoperations-and-nsoperationqueues
Nevertheless, because OAuth is such a pain, it will likely make sense to use a third party library. I've never used it before, but here is an example using MGTwitterEngine:
Twitter's statuses/update_with_media on iOS returns 500 error
If you were able to limit use to iOS 5+, then I would highly recommend using the SLRequest object. The advantage of this approach is that you integrate with the iOS users account directly, so they don't have to authenticate through a UIWebView or something cheesy.
To do so, you would simply plug in the appropriate Twitter API url in the following function requestForServiceType:requestMethod:URL:parameters: and obtain your SLRequest object. Then assign the appropriate Twitter ACAccount obtained from the ACAccountStore using requestAccessToAccountsWithType:options:completion:. Finally make your call to performRequestWithHandler, which would then perform your request asynchronously.
The following code will not post in background but it can post across ios versions...
You can use condition for ios versions like below code.This is working code I have implemented and it is working on both ios 5 and 6. Please check in ios 4 to confirm.I think it should work.
#import "Twitter/Twitter.h"
#import "Social/Social.h"
-(IBAction)tweetPost:(id)sender
{
if ([self isSocialAvailable])
{
SLComposeViewController *tweetComposer=[SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeTwitter]) {
SLComposeViewControllerCompletionHandler __block completionHandler=
^(SLComposeViewControllerResult result){
[tweetComposer dismissViewControllerAnimated:YES completion:nil];
switch(result){
case SLComposeViewControllerResultCancelled:
default:
{
NSLog(#"Cancelled.....");
}
break;
case SLComposeViewControllerResultDone:
{
NSLog(#"Posted....");
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Sent"
message:nil
delegate:nil
cancelButtonTitle:#"Dismiss"
otherButtonTitles: nil];
[alert show];
}
break;
}};
NSString*message = #"posting to twitter test ios 6";
[tweetComposer setInitialText:message];
[tweetComposer addImage:[UIImage imageNamed:#"2.jpg"]];
[tweetComposer addURL:[NSURL URLWithString:#"http://www.youtube.com/watch?v=GoZ2Be2zLq8"]];
[tweetComposer setCompletionHandler:completionHandler];
[self presentViewController:tweetComposer animated:YES completion:nil];
}
}
else
{
TWTweetComposeViewController *twitter= [[TWTweetComposeViewController alloc] init];
[twitter addImage:[UIImage imageNamed:#"2.jpg"]];
[twitter addURL:[NSURL URLWithString:#"http://www.youtube.com/watch?v=GoZ2Be2zLq8"]];
[twitter setInitialText:#"Tweet from iOS 5 app using the Twitter framework."];
[self presentModalViewController:twitter animated:YES];
twitter.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
NSString *title = #"Tweet Status";
NSString *msg;
if (result == TWTweetComposeViewControllerResultCancelled)
msg = #"Tweet compostion was canceled.";
else if (result == TWTweetComposeViewControllerResultDone)
msg = #"Tweet composition completed.";
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:#"Okay" otherButtonTitles:nil];
[alertView show];
};
}
}
-(BOOL)isSocialAvailable {
return NSClassFromString(#"SLComposeViewController") != nil;
}
You need to include three frameworks named social,adSupport and Accounts.Check which one not needed with twitter feed post.
Hope ,this will help you.
Yes, but you'll need find some 1.1 API wrapper (thing which generates API requests, singns them etc) for you and authoriser (MGTWitter engine works fine). I have a working solution for sharing (text only) and getting user info for iOS 4+.
And about background part - that depends on how you implement that (i.e. notifications or continious background execution or gps callbacs etc...).

How to implement AdMob in Phonegap

I have a phonegap application and im trying to implementing Admob.
I'm using phonegap version 1.4.1 and I am using this site as my reference : http://iphone.keyvisuals.com/iphonedev/implementing-admob-ads-in-a-phonegap-project-for-ios-no-plugins-required/
My code is as follows:
(void)webViewDidFinishLoad:(UIWebView *)theWebView
{
bannerView_ = [[GADBannerView alloc]init];
[bannerView_ setDelegate:self];
[bannerView_ setFrame:CGRectMake(0, 0, 320, 50)];
// Specify the ad's "unit identifier." This is your AdMob Publisher ID.
bannerView_.adUnitID = MY_BANNER_UNIT_ID;
// Let the runtime know which UIViewController to restore after taking
// the user wherever the ad goes and add it to the view hierarchy.
bannerView_.rootViewController = self.viewController;
[self.viewController.view addSubview:bannerView_];
// Initiate a generic request to load it with an ad.
[bannerView_ loadRequest:[GADRequest request]];
// only valid if AdGap.plist specifies a protocol to handle
if(self.invokeString)
{
// this is passed before the deviceready event is fired, so you can access it in js when you receive deviceready
NSString* jsString = [NSString stringWithFormat:#"var invokeString = \"%#\";", self.invokeString];
[theWebView stringByEvaluatingJavaScriptFromString:jsString];
}
return [ super webViewDidFinishLoad:theWebView ];
}
Everything is fine, but when I am running the application, no ads are being displayed.
Please make sure that your "theWebView" object finishes its webload. And that the bannerView_ is a registered property of your object.
Also, I hope you just put in "MY_BANNER_UNIT_ID" to hide your banner unit id.
Check up with your admob settings if the banner unit id is correct.
And finally, please use a iphone proxy like Charles or similar to validate that the call goes out as it should.
Phonegap has been upgraded. It support new features. just add this code in your config.
<gap:plugin name="com.admob.plugin" version="1.0.0" source="plugins.cordova.io"/>

How to access Twitter Account Followers into iphone using iOS5? [duplicate]

This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Get twitter Follower in IOS 5
How to access Twitter Account Followers into iphone using iOS5?
I am new to iOS5 , can u please suggest with some code or links.
Thanks in Advance
Bhaskar
In IOS5 twitter is intregated.... then No Use Extra frameWork...
try this code
- (void)OnTwitter {
Class TWTweetComposeViewControllerClass = NSClassFromString(#"TWTweetComposeViewController");
if (TWTweetComposeViewControllerClass != nil) {
if([TWTweetComposeViewControllerClass respondsToSelector:#selector(canSendTweet)]) {
UIViewController *twitterViewController = [[TWTweetComposeViewControllerClass alloc] init];
[twitterViewController performSelector:#selector(setInitialText:)
withObject:twitterText];
[twitterViewController performSelector:#selector(addURL:)
withObject:[NSURL URLWithString:url]];
[twitterViewController performSelector:#selector(addImage:)
withObject:urImage];
[self presentModalViewController:twitterViewController animated:YES];
[twitterViewController release];
}
else {
// Use ShareKit for previous versions of iOS
}
}
import the farmeWork in your Class
#import <Twitter/Twitter.h>
#import <Accounts/Accounts.h>
You can use this link to find how to access twitter accounts
Then you can easily use the API to find the followers

Limit providers while integrating Gigya in iPhone?

I am integrating Gigya in my iphone app. Now it provides 17 providers for access, I want to limit it to just 9 providers. How can I do that?
Has any one integrated it for iPhone? It loads a web view which displays 17 providers in a grouped table format, see here.
To set Facebook and Twitter you can use following code.
GSDictionary *pParams5 = [[GSDictionary new] autorelease];
[pParams5 putStringValue:#"facebook,twitter" forKey:#"enabledProviders"];
[gsAPI showAddConnectionsUI:pParams5 delegate:self context:nil];
GSAPI *gsAPI // declare this
gsAPI = [[GSAPI alloc] initWithAPIKey:<API-KEY> viewController:self]; // i kept this in viewDidload
// add this code to have facebook and twitter on provider list
GSDictionary *pParams5 = [[GSDictionary new] autorelease];
[pParams5 putStringValue:#"facebook,twitter" forKey:#"enabledProviders"];
[gsAPI showAddConnectionsUI:pParams5 delegate:self context:nil];
//this method called when login fails
-(void)gsLoginUIDidFail:(int)errorCode errorMessage:(NSString*)errorMessage context:(id)context{ }
// this method called on successful login
- (void) gsLoginUIDidLogin:(NSString*)provider user:(GSDictionary*)user context:(id)context {}
Check whether you have valid API