I've listed here Yahoo Integration steps which I've followed.
- Step 1. I went to http://developer.yahoo.com/social/sdk/objectivec/
- Step 2. Downloaded entire framework from here - http://github.com/yahoo/yos-social-objc
- Step 3. I did Drag & drop that framework into my project.
- Step 4. Enabled flag
fno-objc-arc
for yahoo framework files. - Step 5. I did
#import "YOSSocial.h"
in my viewController's header file. - Step 6. In view did load, I placed Code block 1 to create a session object.
- Step 7. On a button click, I invoke, Code block 2.
- Step 8. In AppDelegate.m, I've implemented method as Code block 3.
- Step 9. I receive
oauth_token
&oauth_verifier
in redirection.
Code block 1
- (void)viewDidLoad {
[super viewDidLoad];
self.session = [YOSSession sessionWithConsumerKey:@"ConsumerKeyHere"
andConsumerSecret:@"ConsumerSecretKeyHere"
andApplicationId:@"AppKey"];
BOOL hasSession = [self.session resumeSession];
if(hasSession == FALSE) {
// custom call back URL which will redirect to our-app.
// 10.0.0.76/iOS/callback.php redirects
// to com.mymobileapps.currentApp.yahoo
[self.session
sendUserToAuthorizationWithCallbackUrl:
@"http://10.0.0.76/iOS/callback.php"];
} else {
[self sendRequests];
}
}
Code block 2
- (void)sendRequests {
// initialize a user request for the logged-in user
YOSUserRequest *request = [YOSUserRequest requestWithSession:self.session];
// fetch the user's profile data
[request fetchProfileWithDelegate:self];
}
- (void)requestDidFinishLoading:(YOSResponseData *)data {
// parse the response text string into a dictionary
NSDictionary *rspData = [NSJSONSerialization JSONObjectWithData:[data.responseText dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
NSDictionary *profileData = [rspData objectForKey:@"profile"];
// format a string using the nickname object from the profile.
NSString *welcomeText = [NSString stringWithFormat:@"Hey %@ %@!",
[profileData objectForKey:@"givenName"],
[profileData objectForKey:@"familyName"]];
NSLog(@"welcometext is %@",welcomeText);
self.lblProfile.text = welcomeText;
}
Code block 3
- (BOOL)application: (UIApplication *)application
openURL: (NSURL *)url
sourceApplication: (NSString *)sourceApplication
annotation: (id)annotation {
NSString *str = [[url description] stringByReplacingOccurrencesOfString:@"com.mymobileapps.currentApp.yahoo://oauth-response?oauth_token=" withString:@""];
NSArray *ar = [str componentsSeparatedByString:@"&oauth_verifier="];
NSLog(@"oauth_token is %@",[ar objectAtIndex:0]);
NSLog(@"oauth_verifier is %@",[ar objectAtIndex:1]);
// How my session will get updated now with valid authentication done?
return YES;
}
I followed each & every step as described here - http://developer.yahoo.com/social/sdk/objectivec/ & I also implemented redirection as described here - How to redirect from Yahoo to my IOS app after authentication?
QUESTION is as follows. I am still not able to fetch user-profile details like gender, date of birth etc. That is - From Code block 2, I receive data as nil.
What is missing in my code to retrieve data of user-profile?
Other reference.
- (BOOL)application: (UIApplication *)application
openURL: (NSURL *)url
sourceApplication: (NSString *)sourceApplication
annotation: (id)annotation {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
Above code illustrates How Google+ framework handles redirection & manages with local session. In case of Yahoo, I don't find any details which is helpful to update local-session of mobile app.
Edit:
If it is not possible through Yahoo OAuth, How is it possible to fetch basic profile details (like - gender, date of birth, email ID, name etc.) from Yahoo?
fetchProfileWithDelegate:
in Code Block 2 As session within application doesn't have authentication, App will receive nothing from yahoo. – Godsey