简体   繁体   English

雅虎验证和获取配置文件详细信息iOS

[英]Yahoo authenticate & fetch profile details iOS

I've listed here Yahoo Integration steps which I've followed. 我在这里列出了我遵循的Yahoo Integration步骤

  • Step 1. I went to http://developer.yahoo.com/social/sdk/objectivec/ 第1步。我去了http://developer.yahoo.com/social/sdk/objectivec/
  • Step 2. Downloaded entire framework from here - http://github.com/yahoo/yos-social-objc 第2步。从这里下载整个框架 - http://github.com/yahoo/yos-social-objc
  • Step 3. I did Drag & drop that framework into my project. 第3步。我将该框架拖放到我的项目中。
  • Step 4. Enabled flag fno-objc-arc for yahoo framework files. 步骤4.为yahoo框架文件启用标志fno-objc-arc
  • Step 5. I did #import "YOSSocial.h" in my viewController's header file. 步骤5.我在viewController的头文件中执行了#import "YOSSocial.h"
  • Step 6. In view did load, I placed Code block 1 to create a session object. 步骤6.在视图中加载,我放置代码块1来创建会话对象。
  • Step 7. On a button click, I invoke, Code block 2 . 步骤7.单击按钮,我调用代码块2
  • Step 8. In AppDelegate.m, I've implemented method as Code block 3 . 步骤8.在AppDelegate.m中,我将方法实现为代码块3
  • Step 9. I receive oauth_token & oauth_verifier in redirection. 步骤9.我在重定向中收到oauth_tokenoauth_verifier

Code block 1 代码块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 代码块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 代码块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? 我遵循了这里描述的每一步 - http://developer.yahoo.com/social/sdk/objectivec/我还实现了重定向,如此处所述 - 如何在身份验证后从Yahoo重定向到我的IOS应用程序?

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. 我仍然无法获取性别,出生日期等用户个人资料详细信息。这是 - 从代码块2 ,我收到的数据为零。

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. 上面的代码说明了Google+框架如何处理重定向并使用本地会话进行管理。 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? 如果通过Yahoo OAuth无法实现, 如何从雅虎获取基本的个人资料详细信息(如性别,出生日期,电子邮件ID,姓名等)?

Here is the solution. 这是解决方案。

NOTE: You would be needing an intermediate server for that. 注意:您将需要一个中间服务器。

  • Step 01. Download PHP yahoo framework http://github.com/yahoo/yos-social-php 步骤01.下载PHP yahoo框架http://github.com/yahoo/yos-social-php
  • Step 02. Start WAMP/XAMPP server. 步骤02.启动WAMP / XAMPP服务器。
  • Step 03. Obtain URL 步骤03.获取URL
    • example - http://10.0.0.76/iOS/yos-social-php-master/sample/sampleapp.php 示例 - http://10.0.0.76/iOS/yos-social-php-master/sample/sampleapp.php
  • Step 04. Get back to XCode project. 步骤04.返回XCode项目。
  • Step 05. Open XIB, Put a button for Yahoo & connect IBAction method. 步骤05.打开XIB,为Yahoo选择一个按钮并连接IBAction方法。
  • Step 06. In IBAction method, navigate to obtained URL from iOS App to URL. 步骤06.在IBAction方法中,导航到从iOS App到URL的获取URL。 See Code Block 1 参见代码块1
  • Step 07. Add method in AppDelegate.m for handling redirection from Server to your mobile App. 步骤07.在AppDelegate.m中添加方法,用于处理从服务器到移动应用程序的重定向。 See Code Block 2 参见代码块2
  • Step 08. Make sure your app is capable handling Redirection. 步骤08.确保您的应用程序能够处理重定向。 Open your project-info.plist as source-code & make sure you have valid URL types , URL identifier & URL Schemes . 打开project-info.plist作为源代码并确保您拥有有效的URL typesURL identifierURL Schemes as indicated in Code Block 3 代码块3所示
  • Step 09. Now your mobile app is ready for redirection from server. 步骤09.现在您的移动应用程序已准备好从服务器重定向。
  • Step 10. Open yourLocalServer/iOS/yos-social-php-master/sample/sampleapp.php file. 步骤10.打开yourLocalServer/iOS/yos-social-php-master/sample/sampleapp.php文件。 ( https://github.com/yahoo/yos-social-php/blob/master/sample/sampleapp.php ) https://github.com/yahoo/yos-social-php/blob/master/sample/sampleapp.php
  • Step 11. Comment code from 97 to 106. 步骤11.注释代码从97到106。
  • Step 12. Put code as indicated in Code Block 4 步骤12.按照代码块4中的说明放置代码
  • Step 13. Run your project, Click on button from iOS App. 步骤13.运行项目,单击iOS App中的按钮。
  • Step 14. App will navigate to your site-page. 步骤14.应用程序将导航到您的站点页面。 Site page will do the authentication & get the profile details. 网站页面将进行身份验证并获取个人资料详细信息。
  • Step 15. As soon as authentication is done, site-page will redirect back to your-mobile-app with details like - Gender, Full name, date of birth, guid, profile picture url etc. 步骤15.一旦身份验证完成,网站页面将重定向回您的移动应用程序,其详细信息包括 - 性别,全名,出生日期,guid,个人资料图片网址等。

Summary 摘要

Mobile App navigates to Server -> Server manages authentication via OAuth-php. 移动应用程序导航到服务器 - >服务器通过OAuth-php管理身份验证。 Once authenticated Server retrieves profile details & server indicates safari to navigate back to - your-mobile-App. 经过身份验证的服务器检索配置文件详细信息,服务器指示safari导航回 - your-mobile-App。 Your-mobile-app gets all details in Code Block 您的移动应用程序获取Code Block中的所有详细信息

Code Block 1 代码块1

- (IBAction)connectYahoo:(id)sender {
      [[UIApplication sharedApplication] 
           openURL:[NSURL URLWithString:
           @"http://yourLocalServer/iOS/yos-social-php-master/sample/sampleapp.php"
      ]];
}

Code Block 2 代码块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;
}

Code block 3 代码块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>

Code block 4 代码块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: ( source here ) builds a URL and sets some header info, then passes this data to [YOSRequestClient -sendAsyncRequestWithDelegate:] ( source here ). fetchProfileWithDelegate: source here )构建一个URL并设置一些头信息,然后将这些数据传递给[YOSRequestClient -sendAsyncRequestWithDelegate:]这里是源码 )。

The request client then creates a NSMutableURLRequest and NSURLConnection and starts a connection. 然后,请求客户端创建NSMutableURLRequestNSURLConnection并启动连接。

Once the data is downloaded (if any) YOSResponseData takes over and creates a new object from the downloaded data ( source code here ). 下载数据后(如果有的话), YOSResponseData接管并从下载的数据中创建一个新对象( 此处为源代码 )。

There is no code path I can see that would allow the serviceResponseData object passed in to be nil . 没有我能看到的代码路径允许传入的serviceResponseData对象为nil You should at least be able to see [data didSucceed] , which will tell you if the HTTP response was < 400 . 您至少应该能够看到[data didSucceed] ,它会告诉您HTTP响应是否< 400 Oddly enough, if the server just opens and closes the connection with no HTTP response, I believe [data didSucceed] == YES even though it obviously didn't succeed (since 0 < 400). 奇怪的是,如果服务器只是打开并关闭没有HTTP响应的连接,我相信[data didSucceed] == YES即使它显然没有成功(因为0 <400)。

It doesn't look like you're doing anything wrong. 看起来你做错了什么。 My guess is that since the last commit was 4 years ago , and the company has gone through significant restructuring since then, the project has been abandoned and nobody has bothered making a note of it. 我的猜测是,自从上次提交是4年以来 ,该公司从那时起经历了重大的重组,该项目已被放弃,没有人打扰记录它。

Update: In addition to having no updates for 4 years, Yahoo's developer forum for this software has been closed . 更新:除了4年没有更新,雅虎的该软件开发者论坛已经关闭 I don't think Yahoo's API for this software is working any more. 我不认为雅虎的这个软件的API正在运行。 -

From the Yahoo docs you linked here are a few things to check: 在这里链接的雅虎文档中有几点要检查:

  • Check that you are requesting and receiving approval for the correct permissions from the user 检查您是否正在请求并获得用户的正确权限的批准

  • Inspect the YOSResponseData object, if an error occurred it should contain an NSError object. 检查YOSResponseData对象,如果发生错误,它应包含NSError对象。

  • It also contains an NSHTTPURLResponse object. 它还包含NSHTTPURLResponse对象。 Check the response header and status code. 检查响应标头和状态代码。

You've probably checked this stuff already, if so add the results to the question. 您可能已经检查了这些内容,如果是这样,请将结果添加到问题中。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM