Twitter has deprecated its API 1.0 and implemented new API 1.1
As per the new API we need to authentication before fetching the public time line.
I read the new API documentation here: https://dev.twitter.com/docs/api/1.1
but I have not clear idea, how to implement it in iOS.
Can anyone tell me the best way to fetch public time-line form Twitter using the API 1.1
Thanks in advance.
First, you need to Authenticate your request (Get permission).
second, see follow these steps:
1.Download FHSTwitterEngine Twitter Library.
2.Add the folder FHSTwitterEngine" to your project and #import "FHSTwitterEngine.h".
3.add SystemConfiguration.framework to your project.
Usage : 1.in the [ViewDidLoad] add the following code.
UIButton *logIn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
logIn.frame = CGRectMake(100, 100, 100, 100);
[logIn setTitle:#"Login" forState:UIControlStateNormal];
[logIn addTarget:self action:#selector(showLoginWindow:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:logIn];
[[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:#"<consumer_key>" andSecret:#"<consumer_secret>"];
[[FHSTwitterEngine sharedEngine]setDelegate:self];
and don't forget to import the delegate FHSTwitterEngineAccessTokenDelegate.
you need to get the permission for your request, with the following method which will present Login window:
- (void)showLoginWindow:(id)sender {
[[FHSTwitterEngine sharedEngine]showOAuthLoginControllerFromViewController:self withCompletion:^(BOOL success) {
NSLog(success?#"L0L success":#"O noes!!! Loggen faylur!!!");
}];
}
when the Login window is presented, enter your Twitter Username and Password to authenticate your request.
add the following methods to your code:
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[FHSTwitterEngine sharedEngine]loadAccessToken];
NSString *username = [[FHSTwitterEngine sharedEngine]loggedInUsername];// self.engine.loggedInUsername;
if (username.length > 0) {
lbl.text = [NSString stringWithFormat:#"Logged in as %#",username];
[self listResults];
} else {
lbl.text = #"You are not logged in.";
}
}
- (void)storeAccessToken:(NSString *)accessToken {
[[NSUserDefaults standardUserDefaults]setObject:accessToken forKey:#"SavedAccessHTTPBody"];
}
- (NSString *)loadAccessToken {
return [[NSUserDefaults standardUserDefaults]objectForKey:#"SavedAccessHTTPBody"];
}
4.Now you are ready to get your request, with the following method(in this method I created a `Twitter` search for some `Hashtag`, to get the screen_name for example):
- (void)listResults {
dispatch_async(GCDBackgroundThread, ^{
#autoreleasepool {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
// the following line contains a FHSTwitterEngine method wich do the search.
dict = [[FHSTwitterEngine sharedEngine]searchTweetsWithQuery:#"#iOS" count:100 resultType:FHSTwitterEngineResultTypeRecent unil:nil sinceID:nil maxID:nil];
// NSLog(#"%#",dict);
NSArray *results = [dict objectForKey:#"statuses"];
// NSLog(#"array text = %#",results);
for (NSDictionary *item in results) {
NSLog(#"text == %#",[item objectForKey:#"text"]);
NSLog(#"name == %#",[[item objectForKey:#"user"]objectForKey:#"name"]);
NSLog(#"screen name == %#",[[item objectForKey:#"user"]objectForKey:#"screen_name"]);
NSLog(#"pic == %#",[[item objectForKey:#"user"]objectForKey:#"profile_image_url_https"]);
}
dispatch_sync(GCDMainThread, ^{
#autoreleasepool {
UIAlertView *av = [[UIAlertView alloc]initWithTitle:#"Complete!" message:#"Your list of followers has been fetched" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[av show];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
});
}
});
}
That's all. I just got the screen_name from a search Query, you can get a timeline for a user using the following methods:
// statuses/user_timeline
- (id)getTimelineForUser:(NSString *)user isID:(BOOL)isID count:(int)count;
- (id)getTimelineForUser:(NSString *)user isID:(BOOL)isID count:(int)count sinceID:(NSString *)sinceID maxID:(NSString *)maxID;
instead of the search method above.
Note: see the FHSTwitterEngine.h to know what method you need to use.
Note: to get the <consumer_key> and the <consumer_secret> you need to
to visit this link to register your app in Twitter.
You might be interested in the following library.
https://github.com/nst/STTwitter
It is a lightweight Objective-C wrapper for Twitter REST API 1.1.
Look at the ReadMe and Demo project for examples
This is just one of the many methods the library has:
- (void)getUserTimelineWithScreenName:(NSString *)screenName
successBlock:(void(^)(NSArray *statuses))successBlock
errorBlock:(void(^)(NSError *error))errorBlock;
Related
I have an application that i need to integrate with twitter login, for logging in via their twitter account. In the application we also have Twitter sharing option. Here i want to implement functionality to choose their account in which account they want to share the tweet. If user is logged in for only one account, then there should be provision to login to another account without logging out of existing logged-in account.
Well, this really compounds about 5 different topics in to one, and we can't write your entire app for you, but here are some helpful pointers.
When it comes to twitter, I use the STTwitter API (https://github.com/nst/STTwitter). What this does is takes all the twitter code, and dumbs it down for us less objective-c inclined programmers. The "README" file contains more information about what you'd be needing. You can find the developer tutorial at http://www.veasoftware.com/tutorials/2014/6/17/xcode-5-tutorial-ios-7-app-only-authentication-twitter-api-version-11. This also allows you to download the project to test, and copy and paste code from.
Youtube and Google are also great sources to find information. Right now your request is quite broad and encompases quite a few different aspects of twitter integration, work on them one at a time from the ground up.
====>Download Third Party Class FSHTwitterEngine.
{
[[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:#"6XITOIDiXNajx7TQMKOh8qDxj" andSecret:#"w4F44ATueFsarNjGQ9WDdEudJCBJ8P0o5zeNON5bP9hIKhGls6"];
[[FHSTwitterEngine sharedEngine]setDelegate:self];
[[FHSTwitterEngine sharedEngine]loadAccessToken];
UIViewController *loginController = [[FHSTwitterEngine sharedEngine]loginControllerWithCompletionHandler:^(BOOL success) {
NSLog(success?#"L0L success":#"O noes!!! Loggen faylur!!!");
[self performSelector:#selector(TwitterPostMessage) withObject:nil afterDelay:1.0];
}];
[self presentViewController:loginController animated:YES completion:nil];
}
-(void)TwitterPostMessage
{
UIImage *aimg = [UIImage imageNamed:#"mark"];
// [[FHSTwitterEngine sharedEngine]postTweet:#"Hepp adsfihdf sdfhihdsfh" withImageData:UIImagePNGRepresentation(aimg)];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
#autoreleasepool {
//NSString *tweet = [alertView textFieldAtIndex:0].text;
// id returned = [[FHSTwitterEngine sharedEngine]postTweet:#"Post of image"];
id returned = [[FHSTwitterEngine sharedEngine]postTweet:#"Hi Successfully Post Twitter..." withImageData:UIImagePNGRepresentation(aimg)];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSString *title = nil;
NSString *message = nil;
if ([returned isKindOfClass:[NSError class]])
{
NSError *error = (NSError *)returned;
title = [NSString stringWithFormat:#"Error %d",error.code];
message = error.localizedDescription;
} else {
NSLog(#"%#",returned);
title = #"Tweet Posted";
message = #"Post of image";
}
dispatch_sync(dispatch_get_main_queue(), ^{
#autoreleasepool {
UIAlertView *av = [[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[av show];
}
});
}
});
}
My app displays a short list of tweets based on a given TV hashtag with the additional ability to post a tweet.
But now twitter has gone oauth for all requests, my tweet list doesnt appear as it was using the old search.atom API.
Therefore, how do I access the search api and pass in OAuth credentials using Sharekit so user authenticates just the once for viewing tweets and posting between sessions.
I have tried using SHKRequest, hoping, that as ShareKit has already authorised it will pass this information through; with no joy, is there some other way of doing this or am I just using it badly/wrong.
request = [[[SHKRequest alloc] initWithURL:[NSURL URLWithString:#"https://api.twitter.com/1.1/search/tweets.json?q=twitter&result_type=recent"]
delegate:self
isFinishedSelector:#selector(sendFinishedSearch:)
params:nil
method:#"GET"
autostart:YES] autorelease];
I do need to maintain compatibility with 4.3 API so I cant just use iOS5 Twitter API.
Disclaimer: I am inheriting project from someone so my XCode/ObjC knowledge is being learnt whilst I modify project (I come from C/C++ background), so please ignore my ignorance.
ShareKit contains an SHKTwitter class. It is a subclass of SHKOAuthSharer. As such, you can ask it to perform authorisations / refreshes and get the resulting token.
Create an instance of SHKTwitter and register as it's delegate. Implement the - (void)sharerAuthDidFinish:(SHKSharer *)sharer success:(BOOL)success delegate method. Then call tokenRequest. When the delegate method is called, if success is YES you can get the accessToken.
SHKTwitter *twitter = [[SHKTwitter alloc] init];
twitter.shareDelegate = self;
[twitter tokenRequest];
- (void)sharerAuthDidFinish:(SHKSharer *)sharer success:(BOOL)success
{
SHKTwitter *twitter = (SHKTwitter *)sharer;
if (twitter.accessToken != nil) {
NSLog(#"session: %#, %#", twitterSharer.accessToken.key, twitterSharer.accessToken.secret);
} else {
[twitter tokenAccess];
}
}
IN SHKOAuthSharer.m class You will get access Token in method:
- (void)tokenAccessTicket:(OAServiceTicket *)ticket didFinishWithData:(NSData *)data
{
if (SHKDebugShowLogs) // check so we don't have to alloc the string with the data if we aren't logging
SHKLog(#"tokenAccessTicket Response Body: %#", [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease]);
///[[SHKActivityIndicator currentIndicator] hide];
if (ticket.didSucceed)
{
NSString *responseBody = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
//piyush Added
NSArray *strArray = [responseBody componentsSeparatedByString:#"="];
[[NSUserDefaults standardUserDefaults]setObject:[strArray objectAtIndex:([strArray count]-1)] forKey:#"TwitterUsername"];
**self.accessToken** = [[OAToken alloc] initWithHTTPResponseBody:responseBody];
[responseBody release];
[self storeAccessToken];
//[self tryPendingAction];
[[NSNotificationCenter defaultCenter] postNotificationName:#"TwitterDidLogin" object:nil];
}
else
// TODO - better error handling here
[self tokenAccessTicket:ticket didFailWithError:[SHK error:SHKLocalizedString(#"There was a problem requesting access from %#", [self sharerTitle])]];
}
I have found a services from Google which provides to access to Google APIs for various Google Services. I could set up a project in iPhone and create API access for iOS applications (via OAuth2.0) and native applications. I wanted to use the native API for my iPhone app. It API gives me email,fullname,firstname,lastname,google_id,gender,dob,profile_image. How do I use these in my iPhone Application, Any sample apps, snippets available?
Please help me.
Here is my code :
-(void) loadGmail_Login
{
NSString *keychainItemName = nil;
if ([self shouldSaveInKeychain]) {
keychainItemName = kKeychainItemName;
}
// For GTM applications, the scope is available as
NSString *scope = #"http://www.google.com/m8/feeds/";
// ### Important ###
// GTMOAuthViewControllerTouch is not designed to be reused. Make a new
// one each time you are going to show it.
// Display the autentication view.
GTMOAuthAuthentication *auth;
auth = [GTMOAuthViewControllerTouch authForGoogleFromKeychainForName:kKeychainItemName];
GTMOAuthViewControllerTouch *viewController = [[[GTMOAuthViewControllerTouch alloc]
initWithScope:scope
language:nil
appServiceName:keychainItemName
delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)] autorelease];
// You can set the title of the navigationItem of the controller here, if you want.
// Optional: display some html briefly before the sign-in page loads
NSString *html = #"<html><body bgcolor=silver><div align=center>Loading sign-in page...</div></body></html>";
[viewController setInitialHTMLString:html];
[[self navigationController] pushViewController:viewController animated:YES];
}
- (void)viewController:(GTMOAuthViewControllerTouch *)viewController
finishedWithAuth:(GTMOAuthAuthentication *)auth
error:(NSError *)error
{
if (error != nil)
{
// Authentication failed (perhaps the user denied access, or closed the
// window before granting access)
NSLog(#"Authentication error: %#", error);
NSData *responseData = [[error userInfo] objectForKey:#"data"]; // kGTMHTTPFetcherStatusDataKey
if ([responseData length] > 0) {
// show the body of the server's authentication failure response
NSString *str = [[[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding] autorelease];
NSLog(#"%#", str);
}
[self setAuthentication:nil];
}
else
{
// save the authentication object
[self setAuthentication:auth];
// Just to prove we're signed in, we'll attempt an authenticated fetch for the
// signed-in user
[self doAnAuthenticatedAPIFetch];
}
}
- (void)doAnAuthenticatedAPIFetch
{
NSString *urlStr;
// Google Contacts feed
//
// https://www.googleapis.com/oauth2/v2/userinfo
urlStr = #"http://www.google.com/m8/feeds/contacts/default/thin";
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[mAuth authorizeRequest:request];
NSError *error = nil;
NSURLResponse *response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
if (data) {
// API fetch succeeded
NSString *str = [[[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding] autorelease];
NSLog(#"API response: %#", str);
GGCXml_Adaptor *localAlphabetXMLParser = [[GGCXml_Adaptor alloc] init];
[localAlphabetXMLParser processBooksXML:data];
[localAlphabetXMLParser release];
// [self updateUI];
} else {
// fetch failed
NSLog(#"API fetch error: %#", error);
}
}
- (void)setAuthentication:(GTMOAuthAuthentication *)auth {
[mAuth autorelease];
mAuth = [auth retain];
}
First you will need to get token from Google API, For this 1st step you will have to follow this tutorial and in the end of this link there is whole source code for iOS for getting token from google API
http://technogerms.com/login-with-google-using-oauth-2-0-for-ios-xcode-objective-c/
Then in the next step you have to send that token to Google API to request user Data, I just needed the first step So I am sharing my searchings
Try this Tutorial and Source code Link.. It's works fine for me.
1. Tutorial Reference: http://technogerms.com/login-with-google-using-oauth-2-0-for-ios-xcode-objective-c/
2. Api Reference : https://code.google.com/apis/console/
3. Source code: https://github.com/emysa341/Login-with-gmail-google-g--using-oath-2.0-protocol/archive/master.zip
i think this will help anybody else
Follow the below steps to integrate gmail with your application .
1.Add following classes to you project .
GTMHTTPFetcher.h , GTMHTTPFetcher.m ,GTMOAuth2Authentication.h, GTMOAuth2Authentication.m,GTMOAuth2SignIn.h,GTMOAuth2SignIn.m,GTMOAuth2ViewControllerTouch.h,GTMOAuth2ViewControllerTouch.m,GTMOAuth2ViewTouch.xib,SBJSON.h , SBJSON.m
you will get these classes here : https://github.com/jonmountjoy/Force.com-iOS-oAuth-2.0-Example
Note : if you are working under ARC Environment then you have to disable the ARC for following files :
GTMHTTPFetcher.m , GTMOAuth2Authentication.m , GTMOAuth2SignIn.m, GTMOAuth2ViewControllerTouch.m
To disable ARC for source files in Xcode 4, select the project and the target in Xcode. Under the target "Build Phases" tab, expand the Compile Sources build phase, select the library source files, then press Enter to open an edit field, and type -fno-objc-arc as the compiler flag for those files.
2. add the following frameworks
security.framework , systemConfiguration.framework
3. Register your app to google api console …. here : https://code.google.com/apis/console
Then go to ApiAccess section , create client id for iOS app .
then you will get clientID, ClientSecret and RedirectUrl
**4. Now it's time for coding . . . .**
create a signIn button in your controller and set the action for that . Here when the user click the button SignInGoogleButtonClicked method gets called .
//import GTMOAuth2Authentication , GTMOAuth2ViewControllerTouch
#define GoogleClientID #"paster your client id"
#define GoogleClientSecret #"paste your client secret"
#define GoogleAuthURL #"https://accounts.google.com/o/oauth2/auth"
#define GoogleTokenURL #"https://accounts.google.com/o/oauth2/token"
-(void) SignInGoogleButtonClicked
{
NSURL * tokenURL = [NSURL URLWithString:GoogleTokenURL];
NSString * redirectURI = #"urn:ietf:wg:oauth:2.0:oob";
GTMOAuth2Authentication * auth;
auth = [GTMOAuth2Authentication authenticationWithServiceProvider:#"google"
tokenURL:tokenURL
redirectURI:redirectURI
clientID:GoogleClientID
clientSecret:GoogleClientSecret];
auth.scope = #"https://www.googleapis.com/auth/plus.me";
GTMOAuth2ViewControllerTouch * viewcontroller = [[GTMOAuth2ViewControllerTouch alloc] initWithAuthentication:auth
authorizationURL:[NSURL URLWithString:GoogleAuthURL]
keychainItemName:#"GoogleKeychainName" delegate:self
finishedSelector:#selector(viewController:finishedWithAuth:error:)];
[self.navigationController pushViewController:viewcontroller animated:YES];
}
//this method is called when authentication finished
- (void)viewController:(GTMOAuth2ViewControllerTouch * )viewController finishedWithAuth:(GTMOAuth2Authentication * )auth error:(NSError * )error
{
if (error != nil) {
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Error Authorizing with Google"
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
else
{
UIAlertView * alert = [[UIAlertView alloc] initWithTitle:#"Alert !"
message:#"success"
delegate:nil
cancelButtonTitle:#"OK"
otherButtonTitles:nil];
[alert show];
}
}
I am attempting to LIKE a business Facebook Like page (facebook.com/[LikePage]) from my native iOS application. I have used FB iOS SDK for login/logout purpose.
I have implemented the LIKE button similar to http://angelolloqui.com/blog/10-Facebook-Like-Button-on-iOS, which is an implementation of the social plugin on a webview. I did so, because of my understanding that to implement a custom LIKE button, I need to use the Built-in Like provided by FB which in turn would require that my actions be approved by FB.
However, it was brought to my notice that the social plugin implementation cannot be used in an iOS native application and can be used only in a mobile web app.
So, here are my questions :-
Is it true that native iOS applications cannot use the social plugin provided by facebook to like a Facebook Page ?
Is it true that in order to build a custom Like button and not the plugin, I need to use the Built-in Likes provided by Facebook, which in turn would require approval of my action types ? (In my case, LIKE a Page)
All I need is some concrete documentation which clearly lets me know which is the best way forward.
FYI, the business page URL's that need to be LIKEd, come dynamically from server.
Thanks in Advance.
There's no API or automatic method to like facebook pages. The built-in open graph action, once approved, allows you to like other URLs which have Open Graph meta tags on them but not Facebook Pages.
The Like button plugin should work in a webview as far as I know.
You can just use a regular NSURLRequest to like the page, or use another library to make a post call to: https://graph.facebook.com/{PAGE_OR_OBJECT_ID}/likes. Make sure you add the acces_token as a parameter.
I use AFNetworking to post requests:
NSURL *baseURL = [NSURL URLWithString:#"https://graph.facebook.com/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:baseURL];
NSString *link = [NSString stringWithFormat:#"/%#/likes", myObjectID];
NSDictionary *params = #{#"access_token" : FBSession.activeSession.accessToken};
[httpClient postPath:link parameters:params success:^(AFHTTPRequestOperation *op, id result) {
NSLog(#"result %#", result);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"error %#", error);
}];
An update to this post:-
"With the release of the Facebook SDK version 4.28.0, the Like Button for iOS is deprecated. It will be supported until February 5, 2018."
https://developers.facebook.com/docs/sharing/ios/like-button
try this Code:
I think this will surely help you:
Fb like Widget can be embedded in our application. You just have to add a webView and get the Fb Like Widget html code/URL here.
in ViewController.h where you want to add fb like button:
#import <UIKit/UIKit.h>
#interface TestViewController : UIViewController <UIWebViewDelegate>
#property (strong, nonatomic) UIWebView * fbLikeWebView;
-(void)embedFBLikeButton;
#end
in TestViewController.m
#import "AboutUsViewController.h"
#implementation AboutUsViewController
#synthesize fbLikeWebView = _fbLikeWebView;
- (void)viewDidLoad
{
[super viewDidLoad];
//Add this code for FbLike Webview
self.fbLikeWebView = [[UIWebView alloc] initWithFrame: CGRectMake(100.0, 50.0, 55.0, 70.0)];
_fbLikeWebView.opaque = NO;
_fbLikeWebView.backgroundColor = [UIColor clearColor];
_fbLikeWebView.delegate = self;
[self.view addSubview:_fbLikeWebView];
for (UIScrollView *subview in _fbLikeWebView.subviews)
{
if ([subview isKindOfClass:[UIScrollView class]]) {
subview.scrollEnabled = NO;
subview.bounces = NO;
}
}
}
then in ViewWillAppear method call the enbeddFBLikeButton Method to add the fbLike button wigdet on web view:
-(void)viewWillAppear:(BOOL)animated
{
[self embedFBLikeButton];
[_fbLikeWebView reload];
}
-(void)embedFBLikeButton
{
NSString *facebookUrl = //here paste the url you get from fb developer link above;
[self.fbLikeWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:facebookUrl]]];
}
You conform to UIWebViewDelegate now its turn to defining th edelegate method here:
#pragma mark - WebView Delgate Methods
- (BOOL)webView:(UIWebView *)webview shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if ([request.URL.lastPathComponent isEqualToString:#"login.php"])
{
[self login];
return NO;
}
return YES;
}
-(void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
[_fbLikeWebView stopLoading];
}
This method for login the user to facebook Account:
- (void)login
{
[FBSession setActiveSession: [[FBSession alloc] initWithPermissions:#[#"publish_actions", #"publish_stream", #"user_photos"]]];
[[FBSession activeSession] openWithBehavior: FBSessionLoginBehaviorForcingWebView completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
switch (status) {
case FBSessionStateOpen:
// call the legacy session delegate
//Now the session is open do corresponding UI changes
if (session.isOpen) {
FBRequest *me = [FBRequest requestForMe];
[me startWithCompletionHandler: ^(FBRequestConnection *connection,
NSDictionary<FBGraphUser> *my,
NSError *error) {
if (!my) {
NSLog(#"Facebook error:\n%#", error.description);
[[[UIAlertView alloc] initWithTitle: #"Error"
message: #"Facebook Login error."
delegate: self
cancelButtonTitle: #"Ok"
otherButtonTitles: nil, nil] show];
return;
}
}];
[_fbLikeWebView reload];
[[[UIAlertView alloc] initWithTitle: #""
message: #"Successfully Login. Please click on like button"
delegate: self
cancelButtonTitle: #"Ok"
otherButtonTitles: nil, nil] show];
}
break;
case FBSessionStateClosedLoginFailed:
{
[_fbLikeWebView reload];
}
break;
default:
break; // so we do nothing in response to those state transitions
}
}];
}
Enjoy Coding!!!
I'm working with the engine for the first time and am fairly new to iOS development. I' m curious though if there's a way to call a function after I log in successfully? I can't seem to get it to work along the lines that FBConnect called for fbDidLogin after your initial login function. I have MGTwitterEngineDelegate declared and I tried to use the following code after login:
//TWITTER LOGIN FUNCTION/////////////////////
-(void)twitLogin{
NSLog(#"Inside of twitLogin...");
if(![_engine isAuthorized]){
UIViewController *controller = [SA_OAuthTwitterController controllerToEnterCredentialsWithTwitterEngine:_engine delegate:self];
if (controller){
[self presentModalViewController: controller animated: YES];
NSLog(#"Inside of Twitter login UIWebView.");
} else {
NSLog(#"ONCE WE'RE LOGGED IN, LETS SEND THE TWEET!");
NSString *tweet = [[NSString alloc] initWithFormat:#"My Tweet!"];
[_engine sendUpdate:tweet];
NSLog(#"You just tweeted: %#",tweet);
}
} else {
NSString *twitterToken=[[NSUserDefaults standardUserDefaults] objectForKey:#"authData"];
NSLog(#"Twitter is authorized?: %#",twitterToken);
//Twitter Integration Code Goes Here
NSString *tweet = [[NSString alloc] initWithFormat:#"My Tweet!"];
[_engine sendUpdate:tweet];
NSLog(#"You just tweeted: %#",tweet);
}
}
Any help is appreciated. Thanks so much!
The solution I posted previously didn't work %100, turned out I didn't have the right delegate set for login success in my controller:
#pragma mark SA_OAuthTwitterController Delegate
- (void) OAuthTwitterController: (SA_OAuthTwitterController *) controller authenticatedWithUsername: (NSString *) username {
NSLog(#"Authenticated with user %#", username);
tweets = [[NSMutableArray alloc] init];
[self updateStream:nil];
}
Hope that helps anyone!