簡體   English   中英

雅虎驗證和獲取配置文件詳細信息iOS

[英]Yahoo authenticate & fetch profile details iOS

我在這里列出了我遵循的Yahoo Integration步驟

  • 第1步。我去了http://developer.yahoo.com/social/sdk/objectivec/
  • 第2步。從這里下載整個框架 - http://github.com/yahoo/yos-social-objc
  • 第3步。我將該框架拖放到我的項目中。
  • 步驟4.為yahoo框架文件啟用標志fno-objc-arc
  • 步驟5.我在viewController的頭文件中執行了#import "YOSSocial.h"
  • 步驟6.在視圖中加載,我放置代碼塊1來創建會話對象。
  • 步驟7.單擊按鈕,我調用代碼塊2
  • 步驟8.在AppDelegate.m中,我將方法實現為代碼塊3
  • 步驟9.我在重定向中收到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/我還實現了重定向,如此處所述 - 如何在身份驗證后從Yahoo重定向到我的IOS應用程序?

問題如下。 我仍然無法獲取性別,出生日期等用戶個人資料詳細信息。這是 - 從代碼塊2 ,我收到的數據為零。

我的代碼中缺少什么來檢索用戶配置文件的數據?

其他參考。

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

上面的代碼說明了Google+框架如何處理重定向並使用本地會話進行管理。 在雅虎的情況下,我找不到任何有助於更新移動應用程序的本地會話的細節。

編輯:
如果通過Yahoo OAuth無法實現, 如何從雅虎獲取基本的個人資料詳細信息(如性別,出生日期,電子郵件ID,姓名等)?

這是解決方案。

注意:您將需要一個中間服務器。

  • 步驟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
  • 步驟04.返回XCode項目。
  • 步驟05.打開XIB,為Yahoo選擇一個按鈕並連接IBAction方法。
  • 步驟06.在IBAction方法中,導航到從iOS App到URL的獲取URL。 參見代碼塊1
  • 步驟07.在AppDelegate.m中添加方法,用於處理從服務器到移動應用程序的重定向。 參見代碼塊2
  • 步驟08.確保您的應用程序能夠處理重定向。 打開project-info.plist作為源代碼並確保您擁有有效的URL typesURL identifierURL Schemes 代碼塊3所示
  • 步驟09.現在您的移動應用程序已准備好從服務器重定向。
  • 步驟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 App中的按鈕。
  • 步驟14.應用程序將導航到您的站點頁面。 網站頁面將進行身份驗證並獲取個人資料詳細信息。
  • 步驟15.一旦身份驗證完成,網站頁面將重定向回您的移動應用程序,其詳細信息包括 - 性別,全名,出生日期,guid,個人資料圖片網址等。

摘要

移動應用程序導航到服務器 - >服務器通過OAuth-php管理身份驗證。 經過身份驗證的服務器檢索配置文件詳細信息,服務器指示safari導航回 - your-mobile-App。 您的移動應用程序獲取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 .'">';
  }
?>

fetchProfileWithDelegate: source here )構建一個URL並設置一些頭信息,然后將這些數據傳遞給[YOSRequestClient -sendAsyncRequestWithDelegate:]這里是源碼 )。

然后,請求客戶端創建NSMutableURLRequestNSURLConnection並啟動連接。

下載數據后(如果有的話), YOSResponseData接管並從下載的數據中創建一個新對象( 此處為源代碼 )。

沒有我能看到的代碼路徑允許傳入的serviceResponseData對象為nil 您至少應該能夠看到[data didSucceed] ,它會告訴您HTTP響應是否< 400 奇怪的是,如果服務器只是打開並關閉沒有HTTP響應的連接,我相信[data didSucceed] == YES即使它顯然沒有成功(因為0 <400)。

看起來你做錯了什么。 我的猜測是,自從上次提交是4年以來 ,該公司從那時起經歷了重大的重組,該項目已被放棄,沒有人打擾記錄它。

更新:除了4年沒有更新,雅虎的該軟件開發者論壇已經關閉 我不認為雅虎的這個軟件的API正在運行。 -

在這里鏈接的雅虎文檔中有幾點要檢查:

  • 檢查您是否正在請求並獲得用戶的正確權限的批准

  • 檢查YOSResponseData對象,如果發生錯誤,它應包含NSError對象。

  • 它還包含NSHTTPURLResponse對象。 檢查響應標頭和狀態代碼。

您可能已經檢查了這些內容,如果是這樣,請將結果添加到問題中。

您現在可以使用更新的Yahoo iOS SDK而無需執行如此多的步驟: https//github.com/yahoo/yos-social-objc

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM