如何分享帖子和深层链接到我的Android应用程序

时间:2014-05-26 15:13:58

标签: android facebook

我正在尝试在我的Android应用中实现深层链接,到目前为止,我可以发布到我的墙上,但只有发布到google.com的链接(显然这是测试链接)。我希望用户在通过Facebook应用程序点击帖子时导航到我的应用程序,请我需要一步一步的指南,因为我在android编程中不是那么老。这是我的代码:

private void sharePost() {
        // code for sharing the post on facebook
        Session session = Session.getActiveSession();
        session.requestNewPublishPermissions(new Session.NewPermissionsRequest(this, PERMISSIONS));

        Bundle postParams = new Bundle();
        postParams.putString("name", "JSON Twitter");
        postParams.putString("app_name", "JSON Twitter");
        postParams.putString("package", "com.example.jsontwitter");
        postParams.putString("url", "com.example.jsontwitter");
        postParams.putString("caption", "Hello, anyone there ?!");
        postParams.putString("description", "This is a description");
        postParams.putString("link", "https://google.com");
        postParams.putString("class", "com.example.jsontwitter.MainActivity");

         new Request(session, "me/feed", postParams,
         HttpMethod.POST, new Request.Callback() {
         public void onCompleted(Response response) {
         /* handle the result */

         }
         }).executeAsync();
    }

1 个答案:

答案 0 :(得分:0)

需要一个facebook状态回调实现

私有Session.StatusCallback mFBStatuscallback = new Session.StatusCallback(){         @覆盖         public void call(会话会话,SessionState状态,                 异常例外){             onSessionStateChange(session,state,exception);         }     };

然后我不知道你给了什么许可。 但我给予的许可是

    private static final List<String> PERMISSION = Arrays
        .asList("publish_actions","publish_stream");

新的权限请求  设置默认受众并发送回调对象(mFBStatuscallback)

Session.NewPermissionsRequest newPermissionsRequest = new Session.NewPermissionsRequest(
                        (Activity) mCtx, PERMISSION).setDefaultAudience(SessionDefaultAudience.FRIENDS)
                        .setRequestCode(100).setCallback(mFBStatuscallback);
                session.requestNewPublishPermissions(newPermissionsRequest);

和你一样休息。我希望它能奏效。

注意如果您持续多次按下帖子按钮,则只会发布一次消息。之后,发布另一条消息需要一些时间间隔。它是facebook的默认行为

相关问题