我在这里列出了我遵循的Yahoo Integration步骤。
fno-objc-arc
雅虎框架文件的启用标志。#import "YOSSocial.h"
在viewController的头文件中进行了操作。oauth_token
&oauth_verifier
重定向。代码块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应用程序?
问题如下。我仍然无法获取用户配置文件的详细信息,例如性别,出生日期等。也就是说-从代码块2中,我收到的数据为nil。
我的代码中缺少什么来检索用户资料的数据?
其他参考。
- (BOOL)application: (UIApplication *)application
openURL: (NSURL *)url
sourceApplication: (NSString *)sourceApplication
annotation: (id)annotation {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
上面的代码说明了Google+框架如何处理重定向以及如何通过本地会话进行管理。对于Yahoo,我找不到任何有助于更新移动应用本地会话的详细信息。
编辑:
如果无法通过Yahoo OAuth,如何从Yahoo获取基本的个人资料详细信息(例如-性别,出生日期,电子邮件ID,姓名等)?
这是解决方案。
注意:您将需要一个中间服务器。
http://10.0.0.76/iOS/yos-social-php-master/sample/sampleapp.php
URL types
,URL identifier
和URL Schemes
。如代码块3所示yourLocalServer/iOS/yos-social-php-master/sample/sampleapp.php
文件。(https://github.com/yahoo/yos-social-php/blob/master/sample/sampleapp.php)概要
移动应用导航至服务器->服务器通过OAuth-php管理身份验证。身份验证后,服务器会检索配置文件详细信息,并且服务器会指示Safari导航回-your-mobile-App。您的移动应用在代码块中获取所有详细信息
代码块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 .'">';
}
?>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句