Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Is it possible in 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.

  3. If frictionless FB post is available in android, What is the permission that I need to get from user ?

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);
like image 521
iappmaker Avatar asked Nov 18 '15 14:11

iappmaker


1 Answers

  1. Yes
  2. Do not use ShareDialog, instead use ShareApi, here's some sample code
  3. publish_actions permission is required, and your app will be reviewed by Facebook

You may also want to read this Facebook developer post, which seem to discourage implicit/automated posting. 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:

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.

like image 85
Kai Avatar answered Oct 27 '22 00:10

Kai