雅虎认证&获取个人资料详情iOS [英] Yahoo authenticate & fetch profile details iOS
问题描述
我在这里列出了 Yahoo Integration步骤,我已经按照这个步骤。
I've listed here Yahoo Integration steps which I've followed.
- 步骤1.我去了 http://developer.yahoo.com/social/sdk/objectivec/
- 步骤2.从此处下载整个框架 - http ://github.com/yahoo/yos-social-objc
- 第3步。我做了Drag&将该框架放入我的项目中。
- 步骤4.为yahoo框架文件启用标记
fno-objc-arc
。 - 步骤5.我在viewController的头文件中执行了
#importYOSSocial.h
。 - 步骤6.在视图中加载时,我放置代码块1 来创建会话对象。
- 步骤7.单击按钮,我调用代码块2 。
- 步骤8.在AppDelegate.m中,我将方法实现为代码块3 。
- 步骤9.我收到
oauth_token
&重定向中oauth_verifier
。
- 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.
代码块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];
}
}
代码块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;
}
代码块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;
}
我跟着每个&这里描述的每一步 - http://developer.yahoo.com/social/sdk/objectivec / &我还实现了这里描述的重定向 - 如何验证后从Yahoo重定向到我的IOS应用程序?
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?
问题如下所示。
我仍然无法获取性别,出生日期等用户个人资料详情。也就是说 - 从代码区块2 ,我收到数据为无。
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?
其他参考。
- (BOOL)application: (UIApplication *)application
openURL: (NSURL *)url
sourceApplication: (NSString *)sourceApplication
annotation: (id)annotation {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
以上代码说明了Google+框架如何处理重定向&管理本地会话。如果是雅虎,我找不到任何有助于更新移动应用本地会话的详细信息。
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.
编辑:
如果无法通过Yahoo OAuth,如何才能获取基本的个人资料详情(如性别,出生日期,电子邮件ID,姓名等) Yahoo?
推荐答案
以下是解决方案。
注意:您需要一台中间服务器。
NOTE: You would be needing an intermediate server for that.
- 步骤01。下载PHP yahoo框架 http://github.com/yahoo/ yos-social-php
- 步骤02。启动WAMP / XAMPP服务器。
- 步骤03。获取URL
- 示例 -
http://10.0.0.76/iOS/yos-social-php-master/sample /sampleapp.php
- Step 01. Download PHP yahoo framework http://github.com/yahoo/yos-social-php
- Step 02. Start WAMP/XAMPP server.
- Step 03. Obtain URL
- example -
http://10.0.0.76/iOS/yos-social-php-master/sample/sampleapp.php
摘要
Summary
移动应用程序导航到服务器 - >服务器通过OAuth-php管理身份验证。经过身份验证的服务器检索配置文件详细信息和服务器指示safari导航回 - your-mobile-App。您的移动应用程序获取代码块中的所有详细信息
Mobile App navigates to Server -> Server manages authentication via OAuth-php. Once authenticated Server retrieves profile details & server indicates safari to navigate back to - your-mobile-App. Your-mobile-app gets all details in Code Block
代码块1
- (IBAction)connectYahoo:(id)sender { [[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://yourLocalServer/iOS/yos-social-php-master/sample/sampleapp.php" ]]; }
代码块2
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if([[url scheme] isEqualToString:@"com.yourcompany.app.fsq"]) { return [self.obj_LoginHomeVCtr.foursquare handleOpenURL:url]; } else if([[url scheme] isEqualToString:@"com.yourcompany.app.googleplus"]){ return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]; }else if([[url scheme] isEqualToString:@"fb188315544652080"]){ return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication fallbackHandler:^(FBAppCall *call) { NSLog(@"In fallback handler"); }]; } else if ([[url scheme] isEqualToString:@"com.yourcompany.app.yahoo"]){ STLog(@"URL is %@",url); return YES; } return YES; }
代码块3
<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLName</key> <string>com.yourcompany.app.yahoo</string> <key>CFBundleURLSchemes</key> <array> <string>com.yourcompany.app.yahoo</string> </array> </dict> </array>
代码区块4
else if($hasSession && $profile) { $string = "com.yourcompany.app.yahoo://response?birthdate=" . $profile->birthdate . "&familyName=" . $profile->familyName. " " . $profile->givenName . "&gender=" . $profile->gender . "&guid=" . $profile->guid . "&image=" . $profile->image->imageUrl; echo '<meta http-equiv="Refresh" content="1;URL='. $string .'">'; } ?>
这篇关于雅虎认证&获取个人资料详情iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- example -
- 示例 -