我已经实现了faceBook共享。我的代码正在运行,适用于较旧的faceBook AppId。当我在我的帐户中创建一个新的faceBook id时,共享在我的帐户中工作。如果我使用其他用户帐户登录,我将收到授权错误。请帮助。 我的代码是
-(void)Share
{
[SVProgressHUD showWithStatus:@"Posting..." maskType:SVProgressHUDMaskTypeClear];
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
if (!appDelegate.session)
{
appDelegate.session = [[FBSession alloc]initWithPermissions:[NSArray arrayWithObjects:@"publish_actions",nil]];
[self FBShare];
}
else
{
[self FBShare];
}
}
-(void)FBShare
{
if (!FBSession.activeSession.isOpen)
{
NSArray *permissions = [[NSArray alloc] initWithObjects:
@"publish_actions", nil];
[FBSession openActiveSessionWithPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone allowLoginUI:YES
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self postMessage];
}];
}else
if(FBSession.activeSession.isOpen)[self postMessage];
}
-(void)postMessage
{
NSMutableDictionary *parameters=
[NSMutableDictionary dictionaryWithObjectsAndKeys:[Hey %@",_barCode],@"name",
_barImage,@"picture",
@"image/jpeg",@"content_type"
,nil];
FBRequest *request = [FBRequest requestWithGraphPath:@"me/photos" parameters:parameters HTTPMethod:@"POST"];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if(!error)
{
NSLog(@"Posted");
}
else
{
NSLog(@"Error %@",error);
}];
}
我的错误回复是
Error Domain=com.facebook.sdk Code=5 "The operation couldn’t be completed. (com.facebook.sdk error 5.)" UserInfo=0x8ed73f0 {com.facebook.sdk:HTTPStatusCode=403, com.facebook.sdk:ParsedJSONResponseKey={
body = {
error = {
code = 200;
message = "(#200) The user hasn't authorized the application to perform this action";
type = OAuthException;
};
};
code = 403;
headers = (
{
name = Expires;
value = "Sat, 01 Jan 2000 00:00:00 GMT";
},
{
name = "Cache-Control";
value = "no-store";
},
{
name = "Access-Control-Allow-Origin";
value = "*";
},
{
name = Pragma;
value = "no-cache";
},
{
name = "Content-Type";
value = "text/javascript; charset=UTF-8";
},
{
name = "WWW-Authenticate";
value = "OAuth \"Facebook Platform\" \"insufficient_scope\" \"(#200) The user hasn't authorized the application to perform this action\"";
}
);
},com.facebook.sdk:ErrorSessionKey =,expirationDate:2014-08-30 12:08:26 +0000,refreshDate:2014-07-02 05:19:03 +0000,attemptsRefreshDate:0001-12- 30 00:00:00 +0000,权限:( “public_profile” 电子邮件, “联系电子邮件” )>}
答案 0 :(得分:0)
您需要公开您的Facebook AppId。.