新 AppId 的 Facebook 分享问题

Posted

技术标签:

【中文标题】新 AppId 的 Facebook 分享问题【英文标题】:Facebook Share Issue for New AppId 【发布时间】:2014-06-18 15:56:04 【问题描述】:

我已经实现了 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=,过期日期:2014-08-30 12:08:26 +0000,刷新日期:2014-07-02 05:19:03 +0000,尝试刷新日期:0001-12- 30 00:00:00 +0000, 权限:( "public_profile", 电子邮件, “联系电子邮件” )>

【问题讨论】:

publish_stream 已被弃用多年。改用 publish_actions 我不知道为什么每个人都用 publish_stream 发布代码...我认为 Facebook 绝对应该更新文档。 【参考方案1】:

您需要公开您的 facebook AppId..!!

【讨论】:

以上是关于新 AppId 的 Facebook 分享问题的主要内容,如果未能解决你的问题,请参考以下文章

Facebook SDK 3.1 - 分享图片

Facebook iOS SDK - 分享用户照片

Facebook 评论审核、appid 或 Facebook 页面?

友盟分享(微信分享,微博分享,Facebook分享)

分享 Facebook URL(新方式)

javascript Facebook FanPage Badge senza AppId