1

我正在使用 FBConnect 在 facebook 上发布图片。我的代码如下:

- (void) postOnPage
{
    [self saveAccessTokenKeyInfo];

    //post image on wall

    UIImage *img = [UIImage imageNamed:@"image1.png"];
    NSData *data = UIImagePNGRepresentation(img);

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"My hat image", @"message", data, @"source", nil];

    [facebook requestWithGraphPath:@"/me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self];

}

-(void)request:(FBRequest *)request didFailWithError:(NSError *)error{
    NSLog(@"%@", [error localizedDescription]);
    NSLog(@"Err details: %@", [error description]);

    // Stop the activity just in case there is a failure and the activity view is animating.

}

我的控制台打印以下错误日志

The operation couldn’t be completed. (facebookErrDomain error 10000.)
2012-12-10 19:53:56.153 HatApplication[5724:c07] Err details: Error Domain=facebookErrDomain Code=10000 "The operation couldn’t be completed. (facebookErrDomain error 10000.)" UserInfo=0x7fc4da0 {error=<CFBasicHash 0x7fc1120 [0x1b57b48]>{type = mutable dict, count = 3,
entries =>
    2 : <CFString 0x7fc0930 [0x1b57b48]>{contents = "type"} = <CFString 0x7fc30f0 [0x1b57b48]>{contents = "OAuthException"}
    3 : <CFString 0x7fc0d10 [0x1b57b48]>{contents = "message"} = <CFString 0x7fc0cf0 [0x1b57b48]>{contents = "An active access token must be used to query information about the current user."}
    6 : <CFString 0x7f76390 [0x1b57b48]>{contents = "code"} = 2500
}
}

我的代码中缺少什么?

4

1 回答 1

3

在您的方法中尝试这些行:

[self saveAccessTokenKeyInfo];
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"image1" ofType:@"png"];
NSData *videoData = [NSData dataWithContentsOfFile:filePath];
NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:
                                   @"My hat image", @"message", data, @"source", nil];

[facebook requestWithGraphPath:@"/me/photos" andParams:params andHttpMethod:@"POST" andDelegate:self];
于 2012-12-11T03:04:55.613 回答