iOS FBSDKShare API shareWithContent无法发布

时间:2015-05-18 08:12:52

标签: ios facebook facebook-graph-api

我试图使用Facebook iOS Sharing SDK 4.1但没有收到帖子。我有一个活动的会话,但以下代码不会发布到我的feed,并且我也没有得到任何回调(成功,错误或取消),即使调用者是FBSDKSharingDelegate。我试图在SDK文档中模拟示例代码,但无济于事。

if ( [[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"] ) {
    FBSDKShareLinkContent* content = [[FBSDKShareLinkContent alloc] init];
    content.contentURL = _Object.myPostServerURL;
    content.contentDescription = _Object.myPostDescription;
    content.contentTitle = @"New Post";
    content.imageURL = _Object.coverArtServerURL;
    BOOL ok = [[FBSDKShareAPI shareWithContent:content delegate:self] share];
}

我曾尝试使用和不使用"分享"消息包裹在shareWithContent周围;如果需要,我无法从文档中说出来。无论哪种方式,没有回调委托,没有帖子。有人能帮助我吗?

2 个答案:

答案 0 :(得分:1)

   FBSDKShareLinkContent *tempContent=[[FBSDKShareLinkContent alloc] init];
    tempContent.contentTitle=@"hello";
    tempContent.contentDescription=@"desc";
    tempContent.imageURL=[NSURL URLWithString:@"https://camo.githubusercontent.com/67212912f8d2d6a474d1af756603f7c13c837112/687474703a2f2f692e696d6775722e636f6d2f375976386d53412e676966"];
    tempContent.contentURL=[NSURL URLWithString:@"https://scrumptious-facebook.parseapp.com/meals/italian/?fb_action_ids=10200411040395078&fb_action_types=fb_sample_scrumps%3Aeat"];

    _shareAPI.delegate = self;
    _shareAPI.shareContent = tempContent;
    [_shareAPI share];

另外要使用FBSDKShareAPI,你必须通过你获得FBSDKAccessToken来实现你的登录和请求必要的权限,然后只有你可以直接发布到用户feed.This是根据Facebook的文档,如果你想显示自己的共享界面。

目前可能您的delgate可能无法正常工作,但可能是您的应用可能会面临无法访问令牌且没有权限问题的问题

[[[FBSDKLoginManager alloc] init]
     logInWithPublishPermissions:@[publish_actions]
     handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
         if ([result.grantedPermissions containsObject:publish_actions]) {

             [_shareAPI share];
         } else {
             // This would be a nice place to tell the user why publishing
             // is valuable.

         }
     }];


//Delegate methods

- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results{

}
 - (void)sharerDidCancel:(id<FBSDKSharing>)sharer{

}

- (void)sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error{
NSLog(@"%@",error);

}

答案 1 :(得分:0)

您必须在appdelegate中进行一些配置

- (void)applicationDidBecomeActive:(UIApplication *)application {
[FBSDKAppEvents activateApp];
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.}

class MyShop extends Shop {
    var $currency = "EUR";
}