错误:使用 FBConnect 在 facebook 上发布图像



我正在使用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
}
}

我的代码中缺少什么?

在你的方法中尝试以下行:

[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];

相关内容

最新更新