Get Read and Publish Permissions in one request Get Read and Publish Permissions in one request android android

Get Read and Publish Permissions in one request


What ever you saw on Spotify is not the outcome of publish_stream .What they have used is the Open Graph

Open graph concepts involves integrating actions of the app with the FB activity post and share with the users through the application they use. Read more about it at the above mentioned link.


Edits Explanation:Check the Open Graph Permissions

Sample Activity:

public class MainActivity extends Activity implements StatusCallback {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.activity_main);        OpenRequest open = new OpenRequest(this);        open.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);        open.setPermissions(Arrays.asList(new String[]{"email", "publish_actions", "user_birthday", "user_hometown"}));        open.setCallback(this);        Session s = new Session(this);        s.openForPublish(open);    }    @Override    public void call(Session session, SessionState state, Exception exception) {    }    @Override    protected void onActivityResult(int requestCode, int resultCode, Intent data) {        super.onActivityResult(requestCode, resultCode, data);        if(Session.getActiveSession()!=null)            Session.getActiveSession().onActivityResult(this, requestCode, resultCode, data);    }}

This activity will show this (if the user is not logged in):

enter image description here


In my app I have created an instance for OpenRequest and I have set permissions for it.

Session currentSession = Session.getActiveSession();if (currentSession == null || currentSession.getState().isClosed()) {    Session session = new Session.Builder(context).build();    Session.setActiveSession(session);    currentSession = session;}if (currentSession.isOpened()) {    //Do whatever u want. User has logged in}else if(!currentSession.isOpened()){    //Ask for username and password    OpenRequest op = new Session.OpenRequest(context);    op.setLoginBehavior(SessionLoginBehavior.SUPPRESS_SSO);    op.setCallback(null);    List<String> permissions = new ArrayList<String>();    permissions.add("publish_stream");    op.setPermissions(permissions);    Session session = new Builder(InvitePartners.this).build();    Session.setActiveSession(session);    session.openForPublish(op);}

It may be useful to you.


I just set it separately in the onCreate Method.

    LoginButton authButton = (LoginButton) view.findViewById(R.id.authButton);    authButton.setPublishPermissions("publish_actions");    authButton.setFragment(this);    Session.NewPermissionsRequest newPermissionsRequest = new             Session.NewPermissionsRequest(this, Arrays.asList("read_stream"));    Session.getActiveSession().requestNewReadPermissions(newPermissionsRequest);