2015-10-16 36 views
2

我有我的ios應用程序一年的Facebook分享工作正常,並已升級(又名完全重寫)使用最新的api(4.7.x),現在分享不起作用。我檢查了我是否擁有publish_actions權限(我在調用此方法之前執行了此操作,在開放圖形設置,操作類型和功能中檢查了'expicitly shared'。我正在驗證內容(我沒有收到錯誤)並擁有代表,沒有它的方法被調用。ios非對話Facebook分享失敗,沒有錯誤,也沒有反饋

-(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,沒有被公佈。我是不是特別傻在這裏?

+0

這聽起來像一個錯誤,你可以在https://developers.facebook.com/bugs報告,並附上一個小樣本項目? –

回答

0

只是一種可能性,但我發現Facebook的整合已經變得不方便,因爲我發現每次我通過hasGranted:檢查當前令牌被授予許可時,它幾乎即使我幾分鐘前獲得了許可,或者從之前的應用程序啓動時,也總是失敗。

看來,在您的代碼中,如果沒有授予權限,您嘗試登錄並再次獲得權限。但是,當該塊返回時,無論是否授予實際權限,都會拋出錯誤。相反,如果成功,你應該繼續分享。

+0

感謝您指出這個缺陷 - 我在這個方法中添加了權限檢查,以確保我已經授予它,你是對的,我需要重新調整它,一旦我發現我的問題是什麼。我確實擁有權限,因此block沒有執行,[shareAPI share]確實被執行了,它看起來完全沒有任何作用 – wheeliebin