雅虎validation和获取configuration文件的细节iOS

我在这里列出了我所遵循的雅虎集成步骤

  • 第1步。我去了http://developer.yahoo.com/social/sdk/objectivec/
  • 第2步。从这里下载整个框架 – http://github.com/yahoo/yos-social-objc
  • 第3步。我做了拖放该框架到我的项目。
  • 第4步。为雅虎框架文件启用标志fno-objc-arc
  • 第5步。我在我的viewController的头文件中#import "YOSSocial.h"
  • 第6步。鉴于没有加载,我放置代码块1创build一个会话对象。
  • 第7步。按一下button,我调用Code Block 2
  • 第8步。在AppDelegate.m中,我已经实现了代码块3的方法。
  • 第9步。我在redirect中接收oauth_tokenoauth_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/&我也实现了这里描述的redirect – 如何在authentication后从雅虎redirect到我的IOS应用程序?

问题如下。 我仍然无法获取用户configuration文件的详细信息,如性别,出生date等。即从代码块2 ,我收到的数据为零。

我的代码中缺less检索用户configuration文件的数据的是什么?

其他参考。

 - (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation { return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]; } 

以上代码说明了Google+框架如何处理redirect和本地会话pipe理。 在雅虎的情况下,我没有find任何有助于更新本地会话的移动应用程序的细节。

编辑:
如果通过Yahoo OAuth无法实现,那么如何从雅虎获取基本的个人资料信息(如性别,出生date,电子邮件ID,姓名等)?

这是解决scheme。

注意:您将需要一个中间服务器。

  • 步骤01.下载PHP的雅虎框架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
  • 步骤04.返回到XCode项目。
  • 步骤05.打开XIB,为雅虎添加一个button并连接IBAction方法。
  • 步骤06.在IBAction方法中,导航到从iOS App到URL的URL。 见代码块1
  • 步骤07.在AppDelegate.m中添加方法,用于处理从服务器到您的移动应用程序的redirect。 见代码块2
  • 第08步。确保你的应用程序能够处理redirect。 打开你的project-info.plist作为源代码,并确保你有有效的URL typesURL identifierURL Schemes 。 如代码块3所示
  • 步骤09.现在您的移动应用程序已准备好从服务器redirect。
  • 10.打开你的yourLocalServer/iOS/yos-social-php-master/sample/sampleapp.php文件。 ( https://github.com/yahoo/yos-social-php/blob/master/sample/sampleapp.php
  • 步骤11.注释代码从97到106。
  • 第12步。把代码放在代码块4中
  • 第13步。运行你的项目,点击iOS应用程序中的button。
  • 第14步。应用程序将导航到您的网站页面。 网站页面将执行身份validation并获取configuration文件的详细信息。
  • 第15步。身份validation完成后,网站页面将redirect到您的手机应用程序与详细信息,如 – 性别,全名,出生date,guid,个人资料图片url等

概要

移动应用程序导航到服务器 – >服务器通过OAuth-phppipe理身份validation。 一旦通过身份validation的服务器检索configuration文件的详细信息和服务器表示Safari浏览器导航回你的手机应用程序。 您的手机应用程序获取代码块中的所有细节

代码块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 .'">'; } ?> 

fetchProfileWithDelegate: 源代码 )build立一个URL并设置一些头信息,然后将这个数据传递给[YOSRequestClient -sendAsyncRequestWithDelegate:] ( 源在这里 )。

请求客户端然后创build一个NSMutableURLRequestNSURLConnection并启动一个连接。

一旦数据被下载(如果有的话) YOSResponseData接pipe并从下载的数据创build一个新的对象( 源代码在这里 )。

没有代码path,我可以看到,将允许传入的serviceResponseData对象nil 。 您至less应该能够看到[data didSucceed] ,它会告诉您HTTP响应是否< 400 。 奇怪的是,如果服务器只是打开和closures没有HTTP响应的连接,我相信[data didSucceed] == YES即使它显然没有成功(因为0 <400)。

看起来你没有做错什么。 我的猜测是,自从上次提交4年以来 ,公司已经经历了重大的重组,这个项目已经被放弃了,没有人打扰过这个项目。

更新:除了没有更新4年,雅虎的这个软件的开发者论坛已经closures 。 我不认为雅虎的这个软件的API正在工作。 –

从这里链接的雅虎文档是几件事情来检查:

  • 检查您是否正在请求并获得来自用户的正确权限的批准

  • 检查YOSResponseData对象,如果发生错误,它应该包含一个NSError对象。

  • 它还包含一个NSHTTPURLResponse对象。 检查响应标题和状态码。

你可能已经检查过这个东西了,如果是的话,把结果添加到问题中。

您现在可以使用更新的Yahoo iOS SDK,而无需执行如此多的步骤: https : //github.com/yahoo/yos-social-objc