簡體   English   中英

Android:使用SDK 4.0在Facebook中共享OpenGraph Stories

[英]Android: OpenGraph Stories sharing in Facebook with SDK 4.0

我正在嘗試實現玩家解鎖徽章時與Facebook分享的成就。 使用Facebook開發人員控制台中的對象瀏覽器創建了一個對象。 我制作了動作類型和對象類型,並制作了一個自定義故事。 現在,我被困在試圖將故事分享給Facebook。 Facebook提供的文檔不足。 即使是Facebook提供的示例代碼也使用v3.x

下面是facebook給出的示例代碼。 找不到任何好的文檔。

對象代碼

Bundle params = new Bundle();
Request request = new Request(
    Session.getActiveSession(),
    "me/objects/enguru_app:badge",
    params,
    HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response

行動守則

Bundle params = new Bundle();
params.putString("badge", "http://samples.ogp.me/1114467558579559");
Request request = new Request(
    Session.getActiveSession(),
    "me/enguru_app:unlocked",
    params,
    HttpMethod.POST
);
Response response = request.executeAndWait();
// handle the response

在最后想出了我自己的問題。

解決方法如下:

ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("og:type", "enguru_app:badge")
            .putString("og:title", "Unlocked Newbie Badge")
            .putString("og:url","xxxx")
            .putString("og:image","xxx")
            .putString("game:points", "10")
            .putString("fb:app_id", "xxx")
            .putString("og:description",
                    "We are rocking. Come and Play with us").build();
    // Create an action
    ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType("enguru_app:unlocked")
            .putObject("badge", object).build();
    // Create the content
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
            .setPreviewPropertyName("badge").setAction(action)
            .build();

    ShareDialog.show(Profile.this, content);

希望這對遇到同樣問題的人有所幫助。

參見此頁面: https : //developers.facebook.com/docs/sharing/android尤其是ShareOpenGraphObject和ShareOpenGraphAction。

您也可以通過Scrumptious進行調試: https : //github.com/facebook/facebook-android-sdk/blob/master/samples/Scrumptious/src/com/facebook/scrumptious/SelectionFragment.java#L365

如果您正在尋找不使用ShareDialog共享方法:

ShareApi shareApi = new ShareApi(content);
shareApi.share(new FacebookCallback<Sharer.Result>() {
        @Override
        public void onSuccess(Sharer.Result result) {

        }

        @Override
        public void onCancel() {

        }

        @Override
        public void onError(FacebookException error) {

        }
});

您也可能要檢查shareApi.canShare()

暫無
暫無

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

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