我使用以下代码在facebook上分享了一个链接:
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没有完成,他们可能切换回了应用程序”。
- (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]);
}发布于 2016-04-14 15:47:38
#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];
}
}];
}发布于 2018-01-20 07:36:54
您可以在下面的FBSDKSharingDelegate回调中检查结果字典。
- (void)sharer:(id <FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results如果结果字典为空,则用户实际上并没有在Facebook上发帖。如果是这样的话,它至少应该包含postID。
https://stackoverflow.com/questions/36615486
复制相似问题