ios非Dialog Facebook共享失败,没有错误,没有反馈

时间:2015-10-16 16:38:57

标签: ios facebook facebook-graph-api sharing

我已经在我的ios应用程序中分享了facebook共享一年并升级(也称为完全重写)以使用最新的api(4.7.x)并且现在分享根本不起作用。我检查我是否有publish_actions权限(我在调用此方法之前执行此操作,我已经在开放图表设置,操作类型,功能中进行了明确的共享和检查。我正在验证内容(我没有得到错误)并且有一个委托,没有任何方法被调用。

-(void)shareWithFacebook:(NSString *)message
{
    if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"])
    {
        NIDINFO(@"Facebook sharing has publish_actions permission");
    }
    else
    {
        FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
        [loginManager logInWithPublishPermissions:@[@"publish_actions"]
            handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
            {
                NIDERROR(@"Facebook sharing getting publish_actions permission failed: %@", error);
            }
        ];   
    }

    NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: @{
                                                                                   @"og:type": @"article",
                                                                                   @"og:title": @"Bloc",
                                                                                   @"og:description": message,
                                                                                   @"og:url": @"http://getonbloc.com/download"
                                                                                       }];




    FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];

        // Create the action
    FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:@"mynamespace:Share" object:object key:@"article"];
    [action setString:@"true" forKey:@"fb:explicitly_shared"];

        // Create the content
    FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
    content.action = action;
    content.previewPropertyName = @"article";

            // Share the content
    FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
    shareAPI.shareContent = content;
    shareAPI.delegate = self;

    NSError *error;
    if([shareAPI validateWithError:&error] == NO)
    {
        NIDERROR(@"Facebook sharing content failed: %@", error);
    }

    [shareAPI share];
}

 #pragma mark - FBSDKSharingDelegate

- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
    NIDINFO(@"Facebook sharing completed: %@", results);
}

- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
    NIDERROR(@"Facebook sharing failed: %@", error);
}

- (void) sharerDidCancel:(id<FBSDKSharing>)sharer
{
    NIDINFO(@"Facebook sharing cancelled.");
}

我登录工作,可以拍照。我从facebook api得不到任何反馈,没有任何内容发布。我在这做一些特别愚蠢的事吗?

1 个答案:

答案 0 :(得分:0)

只是一种可能性,但我发现Facebook集成变得不方便,因为我发现每次通过hasGranted:检查当前令牌以获得授予的权限时,即使我在几分钟前获得了许可,它也几乎总是失败,或之前的应用程序启动。

似乎在您的代码中,如果未授予权限,您尝试登录并再次获得权限。但是当该块返回时,无论是否授予实际权限,都会引发错误。相反,如果成功,您应该继续分享。