简体   繁体   English

在Android中无摩擦的Facebook分享

[英]Frictionless facebook sharing in Android

User has to click the post button in the share dialog every time they complete a level.I need to eliminate this hardship for user. 用户每次完成一个级别时都必须单击共享对话框中的帖子按钮。我需要为用户消除这种困难。 As of now I have created a custom story and requesting user to click post every time. 截至目前,我已经创建了一个自定义故事,并要求用户每次都点击发布。

Question : 题 :

  1. I heard of frictionless FB post for the Open graph stories. 我听说Open图形故事的无摩擦FB帖子。 Is it possible in android ? 在android中有可能吗?

  2. If frictionless FB post is available in android, could you please point be the correction in my code that I have pasted below. 如果在android中有可用的无摩擦FB帖子,请指点我在下面粘贴的代码中的更正。

  3. If frictionless FB post is available in android, What is the permission that I need to get from user ? 如果android中有无摩擦FB帖子,我需要从用户那里得到什么许可?

Code

    ShareOpenGraphObject object = new ShareOpenGraphObject.Builder()
            .putString("og:type", "puzzlegameballmania:level")
            .putString("og:title", "Cleared Level-1 !!!")
            .putString("og:image", "http://ixxxxwsz.jpg")
            .putString("og:url", "https://play.google.com/store/apps/details?id=com.gamxxxxx.android")
            .putString("og:description", "Color of the balls matters more. Lets break the goal and go higher !")
            .putString("puzzlegameballmania:level:title", "LEVEL 1")
            .build();

    // Create an action
    ShareOpenGraphAction action = new ShareOpenGraphAction.Builder()
            .setActionType("puzzlegameballmania:clear")
            .putObject("puzzlegameballmania:level", object)
            .build();

    // Create the content
    ShareOpenGraphContent content = new ShareOpenGraphContent.Builder()
            .setPreviewPropertyName("puzzlegameballmania:level")
            .setAction(action) 
            .build();

    ShareDialog.show(AndroidLauncher.this, content);
  1. Yes
  2. Do not use ShareDialog , instead use ShareApi , here's some sample code 不要使用ShareDialog ,而是使用ShareApi ,这里是一些示例代码
  3. publish_actions permission is required, and your app will be reviewed by Facebook 需要publish_actions权限,Facebook将审核您的应用

You may also want to read this Facebook developer post , which seem to discourage implicit/automated posting. 您可能还想阅读此Facebook开发人员帖子 ,这似乎不鼓励隐式/自动发布。 A warning to the user is displayed if the app has not been reviewed. 如果未审核该应用,则会显示对用户的警告。

Edit 编辑


Before using ShareApi , first check to see if the app has the required permission: 在使用ShareApi之前,首先检查应用是否具有所需的权限:

private boolean hasPublishPermission() {
    AccessToken accessToken = AccessToken.getCurrentAccessToken();
    return accessToken != null && accessToken.getPermissions().contains("publish_actions");
}

If not, execute code below to request the permission: 如果没有,请执行以下代码以请求权限:

LoginManager.getInstance().logInWithPublishPermissions(
          this, Arrays.asList("publish_actions"));

If you use ShareApi without the proper permission, it will fail and onError(FacebookException) method will be called, assuming you have passed a FacebookCallback to ShareApi . 如果您没有适当权限的情况下使用ShareApi ,它将失败并且将调用onError(FacebookException)方法,假设您已将FacebookCallback传递给ShareApi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM