2012-10-28 23 views

回答

8

Graph API是您想要開始查看您要查找的數據的位置。對於用戶的照片,請上網: 相冊用戶已經創建了 - https://developers.facebook.com/docs/reference/api/user/ 信息有關的照片 - https://developers.facebook.com/docs/reference/api/photo/

我建議您嘗試使用Graph API探險家不同的查詢: https://developers.facebook.com/tools/explorer 首先確保你問user_photos許可 在查詢中輸入我/相冊可爲您提供已登錄用戶的相冊列表。在結果中點擊相冊的ID即可查看該相冊的相關信息。輸入/照片查看該相冊的照片。

一旦你知道你想要什麼,你可以看看構建在Graph API和其他API之上的iOS SDK,以進行身份​​驗證並獲取你感興趣的內容來抓取照片。

對於iOS SDK的信息上作出要求,請參閱: https://developers.facebook.com/docs/reference/ios/3.1/class/FBRequestConnection#startWithGraphPath%3AcompletionHandler%3A

所以,如果你想看到說照片一張專輯,給定一個album_id,你會用請求的代碼,如:

[FBRequestConnection startWithGraphPath:@"<album_id>/photos" 
    completionHandler:^(FBRequestConnection *connection, id result, NSError *error) { 
     if (!error) { 
      NSLog("Results: %@", result); 
     } 
    } 
]; 

確保您先要求提供user_photos權限。

0
- (IBAction)btnFBTap:(id)sender { 
    [FBSDKProfile enableUpdatesOnAccessTokenChange:YES]; 
    if ([FBSDKAccessToken currentAccessToken]) { 
     [self FBLogin]; 
    } else { 

     FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init]; 
     [login 
     logInWithReadPermissions: @[@"public_profile", @"user_photos"] 
     fromViewController:self 
     handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) { 
      if (error) { 
       // Process error 
      } else if (result.isCancelled) { 
       // Handle cancellations 
      } else { 
       [self FBLogin]; 
       // If you ask for multiple permissions at once, you 
       // should check if specific permissions missing 
      } 
     }]; 
    } 
} 

- (void)FBLogin { 

    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" 
             parameters:@{@"fields":@"id"}] 
    startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) { 
     [[MDManager sharedInstance].loadingView hide]; 
     if (!error) { 
      NSLog(@"fetched user:%@", result); 

      // For more complex open graph stories, use `FBSDKShareAPI` 
      // with `FBSDKShareOpenGraphContent` 
      /* make the API call */ 
      FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc] 
              initWithGraphPath:[NSString stringWithFormat:@"/%@/photos", result[@"id"]] 
              parameters:@{@"type":@"uploaded", 
                 @"fields":@"link,height,width"} 
              HTTPMethod:@"GET"]; 
      [request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, 
                id result, 
                NSError *error) { 
       NSLog(@"%@",result); // Return uploaded photos 

      }]; 
     } 
    }]; 
} 
相關問題