我有一个应用程序即时上传照片,我试图添加上传到用户Facebook粉丝页面(他们管理)的功能。
我遇到的问题是我可以成功将照片上传到粉丝页面,但它没有显示在粉丝页面的时间轴上,它只显示在&下#34;其他人的近期帖子"粉丝页面的一部分。
我显然没有正确上传这些图片。这是我的代码:
ACAccountType * accountType = [_accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[_accountStore requestAccessToAccountsWithType:accountType options:@{ACFacebookAppIdKey: @"XXXXXXXXXXXX", ACFacebookPermissionsKey : @[@"photo_upload",@"publish_stream", @"publish_actions", @"manage_pages"], ACFacebookAudienceKey : ACFacebookAudienceEveryone} completion:^(BOOL granted, NSError *error) {
if (granted) {
NSArray * accounts = [_accountStore accountsWithAccountType:accountType];
NSDictionary *fanPages = [[NSUserDefaults standardUserDefaults] objectForKey:FACEBOOK_PREF_FAN_PAGES_IDS];
//if using fan pages
if (fanPages.count)
{
for (id key in fanPages) {
//id is the key and the access token is the value
NSLog(@"access token:%@, fanpage id: %@", fanPages[key], key);
NSMutableString *requestURL = [NSMutableString stringWithFormat:@"https://graph.facebook.com/%@/photos/", key];
NSURL * url = [NSURL URLWithString:requestURL];
NSDictionary *parameters = @{@"access_token": [fanPages[key] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding], @"no_story":@"0", @"message": hashtags};
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:url parameters:parameters];
[request addMultipartData:UIImageJPEGRepresentation(image, 0.9) withName:@"source" type:@"application/octet-stream" filename:@"media.png"];
//NSLog(@"%@",[accounts lastObject]);
[request setAccount:[accounts lastObject]];
//make request
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
NSLog(@"uploaded for %@",fanPages[key]);
NSString *respData = [[NSString alloc] initWithData:responseData
encoding:NSUTF8StringEncoding];
NSLog(@"responseData %@",respData);
NSLog(@"urlResponse for %@",urlResponse);
[self performSelectorOnMainThread:@selector(removeProgressView) withObject:nil waitUntilDone:NO];
}];
}
}
else
{
//upload to personal timeline
NSURL * url = [NSURL URLWithString:@"https://graph.facebook.com/me/photos"];
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:url parameters:nil];
[request addMultipartData:[hashtags dataUsingEncoding:NSUTF8StringEncoding] withName:@"message" type:@"multipart/form-data" filename:nil];
[request addMultipartData:UIImageJPEGRepresentation(image, 0.9) withName:@"source" type:@"application/octet-stream" filename:@"media.png"];
[request setAccount:[accounts lastObject]];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error) {
[self performSelectorOnMainThread:@selector(removeProgressView) withObject:nil waitUntilDone:NO];
}];
}
} else {
//theres an error or they are not granted
}
关于我做错什么的任何想法?我已经在互联网上搜索了好几天,一切看起来都是正确的。
答案 0 :(得分:0)
事实证明我正在做的一切正确,问题是如果我离开了:
[request setAccount:[accounts lastObject]];
这导致它代表我发布,不会出现在时间轴中。删除此代码可以解决问题,我的所有帖子现在都显示在粉丝页面时间轴上,而不是来自我的Facebook用户帐户。
谢谢Tobi,我知道这是访问令牌,我以为我正确地传递了它,显然我不是。
所以只是为了重新迭代,在发布到粉丝页面时不要使用setAccount,因为它会用你的用户令牌而不是粉丝页面令牌覆盖access_token。