我已经做了一个应用程序,在我的应用程序中我已经整合了Facebook来共享信息。用于Facebook集成的 我在应用程序中使用Graph API。 现在在我的应用程序中,我想在用户的墙上上传照片。 我已经使用此代码在用户的墙上上传照片。如何在iPhone上使用Graph API在Facebook上上传照片?
//上传照片
- (void)uploadPhoto:(id)sender {
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"Image1" ofType:@"jpg"];
NSString *message = [NSString stringWithFormat:@"I think this is a Great Image!"];
NSURL *url = [NSURL URLWithString:@"https://graph.facebook.com/me/photos"];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request addFile:filePath forKey:@"file"];
[request setPostValue:message forKey:@"message"];
[request setPostValue:_accessToken forKey:@"access_token"];
[request setDidFinishSelector:@selector(sendToPhotosFinished:)];
[request setDelegate:self];
[request startAsynchronous];
}
- (void)sendToPhotosFinished:(ASIHTTPRequest *)request {
// Use when fetching text data
NSString *responseString = [request responseString];
NSMutableDictionary *responseJSON = [responseString JSONValue];
NSString *photoId = [responseJSON objectForKey:@"id"];
NSLog(@"Photo id is: %@", photoId);
NSString *urlString = [NSString stringWithFormat:
@"https://graph.facebook.com/%@?access_token=%@", photoId,
[_accessToken stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURL *url = [NSURL URLWithString:urlString];
ASIHTTPRequest *newRequest = [ASIHTTPRequest requestWithURL:url];
[newRequest setDidFinishSelector:@selector(getFacebookPhotoFinished:)];
[newRequest setDelegate:self];
[newRequest startAsynchronous];
}
但是,在这里我得到 responseString是{ “错误”:{ “消息”: “错误校验应用程序”, “类型”: “OAuthException”} }和 照片ID是:(null)
图像不会在用户的墙上上传。 所以,请告诉我如何解决它。
正如我在我的回答中所说的,您必须授权facebook才能获得有效的访问令牌。你在使用iOS的Facebook SDK吗? http://developers.facebook.com/docs/guides/mobile/ios/ – jbat100
我也有同样的问题你解决了吗?如果可以,请告诉造成此错误的原因。 – Vijay