【发布时间】:2011-10-10 13:08:36
【问题描述】:
我做了一个应用程序,在我的应用程序中我集成了 Facebook 来共享信息。 对于 Facebook 集成,我在应用程序中使用了 Graph API。 现在在我的应用程序中,我想在用户的墙上上传照片。 我已使用此代码将照片上传到用户的墙上。
//上传照片
- (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 是 {"error":{"message":"Error validate application.","type":"OAuthException"}} 和 照片 ID 为:(null)
并且图片没有上传到用户的墙上。 所以,请告诉我如何解决它。
【问题讨论】:
-
正如我在回答中所说,您必须授权 facebook 才能获得有效的访问令牌。您使用的是 iOS facebook SDK 吗? developers.facebook.com/docs/guides/mobile/ios
-
我也有同样的问题,你解决了吗?如果是,请告诉这个错误的原因。
标签: iphone objective-c ios-4.2