簡體   English   中英

Facebook iOS SDK 4.0上的顯式共享

[英]Explicit Sharing on Facebook iOS SDK 4.0

我想使用新的iOS 4.0 SDK在Facebook上明確分享一個開放的圖形動作。 以下不起作用。 它顯示在我的活動日志中,但不顯示在我的時間軸上。

// Construct an FBSDKSharePhoto
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = img;
photo.userGenerated = YES;

// Create an object
NSDictionary *properties = @{
                             @"og:type": @"theprose:post",
                             @"og:title": post.title,
                             @"og:description": post.text,
                             @"og:caption": @"A fresh picked Prose for you.",
                             @"og:url": post.url,
                             @"fb:explicitly_shared": @"true"
                             };
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];

// Create an action
FBSDKShareOpenGraphAction *act = [[FBSDKShareOpenGraphAction alloc] init];
act.actionType = @"theprose:share";
[act setObject:object forKey:@"theprose:post"];
[act setPhoto:photo forKey:@"image"];

// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = act;
content.previewPropertyName = @"theprose:post";

[[FBSDKShareAPI shareWithContent:content delegate:nil] share];

拼湊這個頁面的答案,這對我有用:

1.選中“明確共享”框

轉到打開的圖表設置,操作類型,然后選擇自定義操作。 向下滾動到功能部分,確保選中“顯式共享”框。

功能設置

2.設置fb:explicitely_shared On Action

[action setString:@"true" forKey:@"fb:explicitly_shared"];

3.設置動作和對象之間的關系

確保您知道將操作連接到對象的正確方法。 在這種情況下,關鍵是“文章”:

[FBSDKShareOpenGraphAction actionWithType:@"mynamespace:share" object:object key:@"article"]

您可以通過查看在FB應用程序的Open Graph設置中創建的Action Type來找到該鍵。 當您通過Story將Action與Ob​​ject連接時,該關系的新鍵將顯示在Property Name列的Action頁面上。

原始海報使用namespace:property_name格式,而您真正需要的只是該鍵的property_name。 這可能是OP的修復。

4.設置代理,查找錯誤

OP沒有利用FBSDKSharingDelegate功能。 它會報告錯誤並幫助您解決問題:

[[FBSDKShareAPI shareWithContent:content delegate:self] share];

並在self中實現委托方法:

#pragma mark - FBSDKSharingDelegate

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

    NSLog(@"Facebook sharing completed: %@", results);
}

- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error {

    NSLog(@"Facebook sharing failed: %@", error);
}

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

    NSLog(@"Facebook sharing cancelled.");
}

供參考,這是我的工作代碼

    // Create the object
NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: @{
                                                                                   @"og:type": @"mynamespace:article",
                                                                                   @"og:title": myModel.title,
                                                                                   @"og:description": @"myModel.description",
                                                                                   @"og:url": @"http://mywebsite.com"
                                                                                   }];


NSURL *imageURL = [myModel getImageURL];
if (imageURL) {

    FBSDKSharePhoto *photo = [FBSDKSharePhoto photoWithImageURL:imageURL userGenerated:NO];
    [properties setObject:@[photo] forKey:@"og:image"];
}

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;

[shareAPI share];

同樣的問題但在同一帳戶下使用FBSDKShareDialog可以正常工作。 所以問題出在其他方面。

我遇到了同樣的問題。 我的意思是你的代碼中的原因是你在對象中設置fb:explicit_shared屬性而不是在關注動作中。

以下代碼應該可以解決問題。

[action setString:@"true" forKey:@"fb:explicitly_shared"];
  1. 如果您的Facebook應用程序不公開,請確保在“角色”部分中將測試帳戶添加為測試帳戶。

  2. 確保您已請求publish_actions權限: https//developers.facebook.com/docs/facebook-login/ios/permissions

  3. 您沒有為您的電話分配代表,很有可能您沒有收到Facebook返回的錯誤

轉到打開的圖表設置,操作類型,然后選擇自定義操作。 向下滾動到功能部分,確保選中“顯式共享”框。

在此輸入圖像描述

它應該不起作用,因為在4.1版本之前的FB版本中存在一個錯誤: https//developers.facebook.com/bugs/943100005734949/ https://developers.facebook.com/bugs/1563738347248670但是SDK版本4.1這個錯誤是修復的,但與FSDKShareDialog相比,自定義故事/動作/對象的內容以非常不同的方式顯示(((

再檢查清單:FBSDKShareApi僅適用於主線程。 因此,請確保您從那里分享。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM