1

以下のコードを使用して Facebook の友達リストを取得していますが、正常に動作しています。しかし、友達のプロフィール写真も必要です。

NSString  *fbPermissions =  @[ @"user_about_me",@"email",@"user_friends"];
NSString  *apiIdKey = @"App_Key";

ACAccountStore *accountStore = [[ACAccountStore alloc] init];
id options = @{
                   ACFacebookAppIdKey: apiIdKey,
                   ACFacebookPermissionsKey: fbPermissions,
                   ACFacebookAudienceKey: ACFacebookAudienceFriends,
              };

ACAccountType *accountType = [accountStore accountTypeWithAccountTypeIdentifier:    ACAccountTypeIdentifierFacebook];
[accountStore requestAccessToAccountsWithType:accountType options:options completion:^(BOOL granted, NSError *error)
{
     if (granted == YES)
     {
         NSArray *arrayOfAccounts = [accountStore accountsWithAccountType:accountType];

         ACAccount *tempAccount = [arrayOfAccounts lastObject];
         NSString *string =  [NSString stringWithFormat:@"https://graph.facebook.com/me/friends"];

         NSURL *fbURL = [NSURL URLWithString:string];

         SLRequest *fbRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                          requestMethod:SLRequestMethodGET
                                                                    URL:fbURL
                                                             parameters:nil];

             [fbRequest setAccount:tempAccount];

             [fbRequest performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {

                 if (!error)
                 {

                     NSError *jsonError = nil;
                     NSDictionary *data = [NSJSONSerialization JSONObjectWithData:responseData
                                                                          options:NSJSONReadingAllowFragments
                                                                            error:&jsonError];

                     NSMutableArray *array = [data valueForKey:@"data"];
                     NSLog(@"Friends array:- %@",array);



                 }
                 else
                 {
                     [[[UIAlertView alloc]initWithTitle:@"Error"
                                                message:[error description]
                                               delegate:nil
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil, nil] show];
                 }
             }];
         }
     }];

プロフィール写真を取得するために、リクエスト URL を次のように変更しました:-

NSString *string =  [NSString stringWithFormat:@"https://graph.facebook.com/me/friends?fields=picture,name"];

私は次の応答を得ました:-

{
error =     {
    code = 2500;
    message = "An active access token must be used to query information about the current user.";
    type = OAuthException;
};
}

リクエストの URL を以前のものに戻すため、コードが正常に機能するため、アクセス トークンの有効期限エラーがわかりません。

4

1 に答える 1

1

最後にそれは働いた: -

NSString *string =  [NSString stringWithFormat:@"https://graph.facebook.com/me/friends"];

NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me/friends"];

SLRequest *fbRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                   requestMethod:SLRequestMethodGET URL:requestURL parameters:@{@"fields":@"id,name,picture,first_name,last_name,gender"}];
于 2014-02-07T07:17:34.573 に答える