首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何知道facebook分享是否是使用FBSDKShareDialog完成的

如何知道facebook分享是否是使用FBSDKShareDialog完成的
EN

Stack Overflow用户
提问于 2016-04-14 14:37:50
回答 2查看 780关注 0票数 1

我使用以下代码在facebook上分享了一个链接:

代码语言:javascript
复制
FBSDKShareDialog *dialog = [[FBSDKShareDialog alloc] init];

    if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"fbauth2://"]]){
        dialog.mode = FBSDKShareDialogModeNative;
    }
    else {
        dialog.mode = FBSDKShareDialogModeFeedBrowser; //or FBSDKShareDialogModeAutomatic
    }
    FBSDKShareLinkContent *content = [[FBSDKShareLinkContent alloc] init];
    content.contentURL = [NSURL URLWithString:@"http://www.twipply.com"];

    dialog.shareContent = content;
    dialog.delegate = self;
    dialog.fromViewController = self;
    [dialog show];

它在以下情况下返回给didCompleteWithResults委托: 1)从safari webPage完成post。(在这两种情况下,都是取消和完成)。2) fb app发布成功。

现在如何知道链接是否已经发布。在safari的情况下,我们使用postID。但如果是应用程序,则不会返回postID。那么我怎么知道它是否已经被张贴了呢?

我使用了下面的代码,但它总是进入if条件,没有得到postID是通过应用程序发布的情况。这导致了“post没有完成,他们可能切换回了应用程序”。

代码语言:javascript
复制
- (void)sharer:(id<FBSDKSharing>)sharer didCompleteWithResults :(NSDictionary *)results {

     NSURL *fbURL = [NSURL URLWithString:@"fb://"];
    if (![[UIApplication sharedApplication] canOpenURL:fbURL]){
        if (results[@"postId"]) {
            NSLog(@"Sweet, they shared, and Facebook isn't installed.");
            actionTypeSearch = kActionTypeSharing;
            sharingType = @"0";
            [self sendRequestToWeb];
        }
        else {
            NSLog(@"The post didn't complete, they probably switched back to the app");
        }

    } else {
        NSLog(@"Sweet, they shared, and Facebook is installed.");
        actionTypeSearch = kActionTypeSharing;
        sharingType = @"0";
        [self sendRequestToWeb];
    }


    NSLog(@"FB: SHARE RESULTS=%@\n",[results debugDescription]);
}
EN

回答 2

Stack Overflow用户

发布于 2016-04-14 15:47:38

代码语言:javascript
复制
#import <FBSDKLoginKit/FBSDKLoginKit.h>
#import <FacebookSDK/FacebookSDK.h>
#import <FBSDKCoreKit/FBSDKCoreKit.h>

 if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"]) {
        [self shareVideoOnFacebook];
    } else {
        FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
        [loginManager logOut];  //very important line for login to work
        [loginManager logInWithPublishPermissions:@[@"publish_actions"]
                                          handler:^(FBSDKLoginManagerLoginResult result, NSError error) {
                                              if(!error) {
                                                  [self shareVideoOnFacebook];
                                              }
                                              else
                                              {

                                              }
                                          }];
    }
- (void) shareVideoOnFacebook
{
    __weak SharingViewController *weakSelf = self;

    NSString *pathFile = [[NSBundle mainBundle] pathForResource:@"TestVideo" ofType:@"mp4"];

    NSData *videoData = [NSData dataWithContentsOfFile:pathFile];

    NSMutableDictionary *params = [NSMutableDictionary dictionaryWithCapacity:3L];

    [params setObject:videoData forKey:@"video_filename.MOV"];
    [params setObject:@"Title for this post." forKey:@"title"];
    [params setObject:@"Video App" forKey:@"description"];

    [[[FBSDKGraphRequest alloc] initWithGraphPath:@"/me/videos" parameters:params HTTPMethod:@"POST"]
     startWithCompletionHandler:^(FBSDKGraphRequestConnection connection, id result, NSError error) {
         [spinnerView endRefreshing];
         spinnerView.hidden = true;
         self.view.userInteractionEnabled = true;

         if (!error) {
             //video posted
             [[[UIAlertView alloc]initWithTitle:@"" message:@"Send Successfully" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil]show];
         }
         else{
             NSString *strError=@"";
             NSString *strWaringMesssage;
             if ([[[[Common sharedCommon]errorList]allKeys] containsObject:strError])
             {
                 NSString *strWaring=[[[Common sharedCommon]errorList] objectForKey:strError];
                 strWaringMesssage=[dictTemp objectForKey:strWaring];
             }
             else
             {
                 NSString *strWaring= DEFAULT_ERROR_MESSAGE;
                 strWaringMesssage=[dictTemp objectForKey:strWaring];

             }
             ErrorViewController *objErrorViewController =[[ErrorViewController alloc]initWithNibName:@"ErrorViewController" bundle:nil];
             objErrorViewController.strErrorNumber = strWaringMesssage;
             [weakSelf presentViewController:objErrorViewController animated:YES completion:nil];

         }
     }];
}
票数 0
EN

Stack Overflow用户

发布于 2018-01-20 07:36:54

您可以在下面的FBSDKSharingDelegate回调中检查结果字典。

代码语言:javascript
复制
- (void)sharer:(id <FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results

如果结果字典为空,则用户实际上并没有在Facebook上发帖。如果是这样的话,它至少应该包含postID

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36615486

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档