3

我正在尝试获取用户详细信息,但目前无法获取图像。这是我得到的错误:

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

这是我的代码:

   if(!self.store)
    {
        ACAccountStore *store1 = [[ACAccountStore alloc] init];
        self.store=store1;
        [store1 release];

    }

    ACAccountType *fbAccountType =
    [store accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
    NSArray * permissions = @[@"read_stream", @"publish_stream",@"email", @"user_birthday",@"publish_actions",@"user_photos"];
    NSDictionary * dict = @{ACFacebookAppIdKey : @"my_key", ACFacebookPermissionsKey : permissions, ACFacebookAudienceKey : ACFacebookAudienceOnlyMe};
    //  Request permission from the user to access the available Twitter accounts
    [store requestAccessToAccountsWithType:fbAccountType options:dict completion:^(BOOL granted, NSError *error) {
        __block NSString * statusText = nil;
        if (granted) {
            statusText = @"Logged in";
            NSArray * accounts = [store accountsWithAccountType:fbAccountType];
            store = [accounts lastObject];
            account = [accounts objectAtIndex:0];
            NSLog(@"account is: %@", account);
            NSURL *requestURL = [NSURL URLWithString:@"https://graph.facebook.com/me?fields=picture"];
            SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                    requestMethod:SLRequestMethodGET
                                                              URL:requestURL
                                                       parameters:nil];
            request.account = account;
            [request performRequestWithHandler:^(NSData *data,
                                                 NSHTTPURLResponse *response,
                                                 NSError *error) {

                if(!error){
                    NSDictionary *list =[NSJSONSerialization JSONObjectWithData:data
                                                                        options:kNilOptions error:&error];
                    NSLog(@"Dictionary contains: %@", list );
                }
                else{
                    //handle error gracefully
                }

            }];
        }

如果我使用https://graph.facebook.com/me作为 url,那么它工作正常。但我也需要个人资料照片。该怎么办?

4

3 回答 3

4

“字段”是一个参数,而不是 URL 本身的一部分。这有效:

SLRequest *videoLimitsRequest = [SLRequest requestForServiceType:SLServiceTypeFacebook
                                                   requestMethod:SLRequestMethodGET
                                                             URL:[NSURL URLWithString:@"https://graph.facebook.com/me"]
                                                      parameters:@{@"fields": @"video_upload_limits"}];

仅供参考,当您将帐户附加到 SLRequest 时,会自动添加令牌。

于 2013-11-17T20:15:00.460 回答
0

你可以像这样使用 accesstoken 运行 fql

https://graph.facebook.com/fql?q=SELECT name from user where uid = YourFacebookID&access_token=ACCESSTOKEN

这对你有用。

于 2013-02-09T06:09:48.680 回答
0

这有点旧,但我忘了回答。从 FB api 3.2 开始,一切都在 api 中进行管理,用于 bot iOS 5 和 6 本机登录。这是我所做的:

FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
FBRequest *request = [FBRequest requestWithGraphPath:@"me/albums" parameters:nil HTTPMethod:@"GET"];

FBRequestHandler handler =
^(FBRequestConnection *connection, id result, NSError *error)
{

    if(!error)
    {
        NSDictionary *list =(NSDictionary*)result;

        int flag = 0;
        for (int index = 0; index < [[list objectForKey:@"data"] count];index++)
        {
            if ([[[[list objectForKey:@"data"] objectAtIndex:index] objectForKey:@"name"] isEqualToString:@"Profile Pictures"])
            {
                [self fetchAlbumImages:[[[list objectForKey:@"data"] objectAtIndex:index] objectForKey:@"id"]];
                flag = 1;
            }

        }
        if (flag == 0)
        {
            [self fetchAlbumImages:@"No Album"];
        }
    }
    else
    {

    }
};

[newConnection addRequest:request completionHandler:handler];
//[self.requestConnection cancel];


[newConnection start];
[newConnection release];
}

- (void) fetchAlbumImages:(NSString*)albumId
{
    if ([albumId isEqualToString:@"No Album"])
    {
        NSMutableArray *albumArray = [[NSMutableArray alloc]init];
        [self performSelectorOnMainThread:@selector(sendRegistrationRequest:) withObject:albumArray waitUntilDone:YES];
        [albumArray release];
    }
    else
    {
        FBRequestConnection *newConnection = [[FBRequestConnection alloc] init];
        FBRequest *request = [FBRequest requestWithGraphPath:[NSString stringWithFormat:@"%@/photos",albumId] parameters:nil HTTPMethod:@"GET"];

        FBRequestHandler handler =
        ^(FBRequestConnection *connection, id result, NSError *error)
        {

            if(!error)
            {

                NSDictionary *list =(NSDictionary*)result;

                NSMutableArray *albumArray = [[NSMutableArray alloc]init];
                for (int index = 0; index < ([[list objectForKey:@"data"] count]<10?[[list objectForKey:@"data"] count]:10);index++)
                {
                    [albumArray addObject:[[[list objectForKey:@"data"] objectAtIndex:index] objectForKey:@"source"]];
                }

                [self performSelectorOnMainThread:@selector(sendRegistrationRequest:) withObject:albumArray waitUntilDone:YES];
            }
            else
            {

            }
        };

        [newConnection addRequest:request completionHandler:handler];
        //[self.requestConnection cancel];

        self.requestConnection = newConnection;
        [newConnection start];
        [newConnection release];
    }
}
于 2013-08-22T09:04:19.070 回答