簡體   English   中英

與Android Facebook SDK 3.0共享鏈接和文本

[英]Share link and text with Android Facebook SDK 3.0

我試圖升級到Facebook SDK 3.0,並最終得到一切與Request.newStatusUpdateRequest()。 但是,我的應用程序共享/發布文本以及鏈接。 我試過/研究過以下內容:

Request.newStatusUpdateRequest()

這似乎沒有Bundle的任何選項或任何其他方式來包含鏈接和圖標。

Request.newRestRequest()

跳過這個因為我看到REST被折舊了。

new WebDialog.FeedDialogBuilder(_activity, session, params).build().show();

這實際上工作得很好,但結果的帖子似乎沒有鏈接到我的Facebook應用程序,我不知道這將如何影響我的Facebook見解。

Request.newPostRequest()

從我所讀到的,這種方法似乎是正確的方法。 但是,我無法弄清楚將GraphObject作為參數之一傳入的位置。

什么是將文本,鏈接和圖像發布/共享到用戶牆上的PROPPER方式? 它似乎是Request.newPostRequest()所以我將包含我的代碼。

Request request = Request.newPostRequest(session, "me/feed", ??graph_object??, new Request.Callback() {
    @Override
    public void onCompleted(Response response) {
        showPublishResult("message", response.getGraphObject(), response.getError());
    }
});
request.setParameters(params);
Request.executeBatchAsync(request);

但究竟什么是GraphObject? 我在哪里獲得graph_object? 我在GraphObject / OpenGraph / Graph API上從FB讀取的越多,我就越感到困惑。

如果我完全朝着錯誤的方向前進,請告訴我。 如果Request.newPostRequest是執行此操作的方式,請提供有關GraphObject參數的更多信息。

最后使用以下方法設法通過Facebook SDK 3.0獲得我需要的一切:

Bundle params = new Bundle();
params.putString("caption", "caption");
params.putString("message", "message");
params.putString("link", "link_url");
params.putString("picture", "picture_url");

Request request = new Request(Session.getActiveSession(), "me/feed", params, HttpMethod.POST);
request.setCallback(new Request.Callback() {
    @Override
    public void onCompleted(Response response) {
        if (response.getError() == null) {
            // Tell the user success!
        }
    }
});
request.executeAsync();

我用這種方法做了。 看看這是否有幫助。

public static void publishFeedDialog(final Activity current, final String title,
        final String caption, final String description, final String link,
        final String pictureUrl) {
    // start Facebook Login
    Session.openActiveSession(current, true, new Session.StatusCallback() {

        // callback when session changes state
        @Override
        public void call(Session session, SessionState state,
                Exception exception) {
            if (session.isOpened()) {
                Bundle params = new Bundle();
                params.putString("name", title);
                params.putString("caption", caption);
                params.putString("description", description);
                params.putString("link", link);
                params.putString("picture", pictureUrl);

                WebDialog feedDialog = (new WebDialog.FeedDialogBuilder(
                        current, Session.getActiveSession(), params))
                        .setOnCompleteListener(new OnCompleteListener() {

                            @Override
                            public void onComplete(Bundle values,
                                    FacebookException error) {
                                if (error == null) {
                                    // When the story is posted, echo the
                                    // success
                                    // and the post Id.
                                    final String postId = values
                                            .getString("post_id");
                                    if (postId != null) {
                                        ToastHelper.MakeShortText("Posted");
                                    } else {
                                        // User clicked the Cancel button
                                        ToastHelper
                                                .MakeShortText("Publish cancelled");
                                    }
                                } else if (error instanceof FacebookOperationCanceledException) {
                                    // User clicked the "x" button
                                    ToastHelper
                                            .MakeShortText("Publish cancelled");
                                } else {
                                    // Generic, ex: network error
                                    ToastHelper
                                            .MakeShortText("Error posting story");
                                }
                            }

                        }).build();
                feedDialog.show();
            }
        }
    });

分享頁面或鏈接

Bundle params = new Bundle();
params.putString("link", "link_url");


Request request = new Request(Session.getActiveSession(), "me/feed", params, HttpMethod.POST);
request.setCallback(new Request.Callback() {
    @Override
    public void onCompleted(Response response) {
        if (response.getError() == null) {
            // Tell the user success!
        }
    }
});
request.executeAsync();

有關更多帖子參數,請參閱developer.facebook.com上的me / feed

暫無
暫無

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

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