2016-11-25 42 views
0

我們正在使用我們的反應應用程序和我們的原生Android應用程序的網頁版本,因此我們的設置和一切工作正常。我試圖通過react-native-fbsdk實現在react-native中共享一個動作。我遵循Android代碼,因爲它看起來離react-native-fbsdk代碼最近。如何使用react-native-fbsdk共享操作?

我應該使用ShareApi.share還是別的?

我試着創建ShareOpenGraphContent的一個實例來使用ShareApi.share,但沒有構造函數。

我希望他們能提供更完整的文檔:■

基於我的同事用於Android上的ShareApi好像反應,原生fbsdk缺少相關的共享操作的幾件事情的代碼。

ShareOpenGraphContent沒有直接從反應母語-fbsdk遠銷所以這

import { ShareOpenGraphContent } from 'react-native-fbsdk'; 

其實是行不通的。在react-native-fbsdk中必須有一些方法來使用ShareApi來共享一個動作......我只是錯過了一些東西。

有人幫助...請。

謝謝!

回答

0

我想通了!我必須手動創建一個ShareOpenGraphContent對象的實例,它具有3個必需屬性:contentType,action和previewPropertyName。 react-native-fbsdk目前沒有這個對象類型的構造函數。

ShareApi.canShare不是強制性的,但它會在嘗試共享之前檢查以確保您擁有正確的權限。這將允許您在嘗試萬一令牌過期或者用戶尚未同意所需權限之前讓用戶登錄。

const ogAction = new ShareOpenGraphAction('<your_facebook_namespace>' + ':' + '<your_facebook_action>'); 
ogAction.putString('song', 'https://<url_to_your_song_app_etc>'); 
ogAction.putString('place', '<fbPlacePageID>''); 
ogAction.putNumber('fb:explicitly_shared', 1); // Normally this is a boolean, but putNumber with a value of 1 works 

// Manually create an instance of ShareOpenGraphContent (no constructor in the API) 
const ogContent = { 
    contentType: 'open-graph', 
    action: ogAction, 
    previewPropertyName: 'song', 
}; 

ShareApi.canShare(ogContent).then((canShare) => { 
    if (canShare) 
    return ShareApi.share(ogContent, '/me'); 
}).then(
    function(result) { 
    // Shared successfully 
    }, 
    function(error) { 
    // Failed to share 
    } 
); 
相關問題