我很难搞清楚我在这里做错了什么。任何帮助将非常感激。情况就是这样。我有一个图像,我试图自动分享到Facebook。因此,根据Facebook的最佳实践,我首先获得了基本权限,然后我获得了publish_actions权限。当我试图发布图片时,没有发布错误,但NSURLResponse显示了这一点。
"Www-Authenticate" = "OAuth \"Facebook Platform\" \"insufficient_scope\" \"(#200) Permissions error\"";
以下是我用来分享给Facebook的代码。
- (void) loginViaFacebookWithPublishCredentialsWithResponse:(BGResponseBlock)block
{
if(!self.accountStore)
{
self.accountStore = [[ACAccountStore alloc] init];
}
ACAccountType *facebookTypeAccount = [self.accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook];
[self.accountStore requestAccessToAccountsWithType:facebookTypeAccount
options:@{ACFacebookAppIdKey: FacebookAppIDKey,
ACFacebookPermissionsKey: @[@"publish_actions"],
ACFacebookAudienceKey: ACFacebookAudienceEveryone}
completion:^(BOOL granted, NSError *error)
{
if(granted)
{
NSArray *accounts = [self.accountStore accountsWithAccountType:facebookTypeAccount];
self.facebookAccount = accounts.lastObject;
ACAccountCredential *fbCredential = [self.facebookAccount credential];
if([fbCredential oauthToken])
{
if(block)
{
block([fbCredential oauthToken],nil);
}
}
}
else
{
if([error code] == 6)
{
if(block)
{
block(nil,error);
}
}
else
{
NSLog(@"The original error while trying to log into facebook is %@", error);
NSError *accessDeniedError = [NSError errorWithDomain:@"Access Denied" code:999 userInfo:nil];
if(block)
{
block(nil,accessDeniedError);
}
}
}
}];
}
- (void) autoShareViaFacebook:(UIImage *)image withCaption:(NSString *)caption andResponseBlock:(void(^)(BOOL sharedSuccessfullyViaFB, NSError *error))block
{
NSBlockOperation *uploadOperation = [[NSBlockOperation alloc] init];
[uploadOperation addExecutionBlock:^
{
[self loginViaFacebookWithPublishCredentialsWithResponse:^(id responseObject, NSError *error)
{
if(responseObject && !error)
{
NSDictionary *parameters = @{@"message":caption};
SLRequest *request = [SLRequest requestForServiceType:SLServiceTypeFacebook requestMethod:SLRequestMethodPOST URL:[NSURL URLWithString:@"https://graph.facebook.com/me/photos"] parameters:parameters];
request.account = self.facebookAccount;
[request addMultipartData:UIImageJPEGRepresentation(image, 0.8) withName:@"source" type:@"multipart/form-data" filename:caption];
[request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
{
//NSError *jsonParsingError = nil;
if (error)
{
// Post error data to NSLog
NSLog(@"SLRequest Error: %@", error);
if(block)
{
block(NO, error);
}
}
else
{
NSLog(@"Facebook autoshare successful!");
if(block)
{
block(YES,nil);
}
}
}];
}
else
{
dispatch_async(dispatch_get_main_queue(), ^{
if(block)
{
block(NO,error);
}
});
}
}];
}];
[[BGSocialInstance sharedInstance].operationQueue addOperation:uploadOperation];
}
当我打印出NSURLResponse时,这就是我得到的。
po urlResponse
<NSHTTPURLResponse: 0x15e26430> { URL: https://graph.facebook.com/me/photos } { status code: 403, headers {
"Access-Control-Allow-Origin" = "*";
"Cache-Control" = "no-store";
Connection = "keep-alive";
"Content-Length" = 83;
"Content-Type" = "application/json; charset=UTF-8";
Date = "Mon, 16 Jun 2014 17:52:11 GMT";
Expires = "Sat, 01 Jan 2000 00:00:00 GMT";
Pragma = "no-cache";
"Www-Authenticate" = "OAuth \"Facebook Platform\" \"insufficient_scope\" \"(#200) Permissions error\"";
"X-FB-Debug" = "fH7p9jHKmUDEWpa36iKKp0T8zrAu3gyx46oqdzB1fmgEJMEhYuYDgJ33R7lDXfVXG5PGzrQCDXYUxtgh73sFOA==";
"X-FB-Rev" = 1292193;
} }
打印时的响应数据总是给出这个。
resposedata:{"error":{"message":"(#200) Permissions error","type":"OAuthException","code":200}}
答案 0 :(得分:0)
看起来,由于Facebook转移到Graph 2.0,我们需要为我们在developer.facebook.com中创建的应用程序请求publish_actions权限。我们需要提交一个指向隐私政策的链接,填写大量元数据并提交构建版本,FB将审核它并提供对应用程序的访问权限,所有内容都应该与上面的代码一起使用。