20

Before you all say it's not possible, open up the Spotify app and hit the signin with Facebook button.

I'm wondering how they did it, and how I can get "publish_stream" and basic permissions/email in one request.

Also, is it possible for me to reopen a Facebook session using the Facebook SDK if I have certain info from the last session (last time they used the app)?

EDIT -SCREENSHOTS BELOW FOR THE MUSICALLY AVERT

Spotify magic

baconcheese113
  • 843
  • 2
  • 13
  • 27
  • Just because its possible for Spotify doesn't mean the functionality is extended to all other apps. Know any other apps that can open 3rd party computer applications directly from FB? – Tommy Crush Mar 05 '13 at 18:35
  • Are you suggesting that Spotify is piggybacking off Facebook to offset its royalty streaming payments, and that Zuckerberg is promoting the partnership due to his long-acknowledged love for P2P streaming services? ...that's crazy. – baconcheese113 Mar 05 '13 at 19:21

5 Answers5

20

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

Sherif elKhatib
  • 45,786
  • 16
  • 89
  • 106
Vijay
  • 5,331
  • 10
  • 54
  • 88
  • 1
    This is the right answer. Try to add the permission `publish_actions` I will edit this answer and add a test. – Sherif elKhatib Mar 11 '13 at 15:22
  • i exactly trying to do the same FB login(like pinterest) with permission email,basic_info,publish_action in a single request.implemented above code but unable to do so...plz help... – sanjay Apr 06 '13 at 09:14
1

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.

Santhosh
  • 1,962
  • 2
  • 16
  • 23
1

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);
Ethan
  • 179
  • 1
  • 9
0

Go to your application dashboard. then click edit app. now in left side of the page u will see Permission. click it. a new page will come. find out User & Friend Permissions: box. here type publish_actions. now save.

now from your android app you can post story to facebook by login just once. i mean, just login using LoginButton,and try to post something. it should work.

let me know what happen.

Shoshi
  • 2,254
  • 1
  • 29
  • 43
  • This doesn't seem to work from my mobile app. I tried with both my own implementation of session management (openSessionForPublish without already having read permissions) and with the tools that the Facebook SDK provided (com.facebook.widget.LoginButton and setting Read and Publish permissions). Both throw errors saying you can't request both at the same time. – baconcheese113 Mar 05 '13 at 15:55
  • Then it only prompts for the read permission. openSessionForRead("app_id", "permission_list") – baconcheese113 Mar 05 '13 at 19:22
  • r u using Facebook SDK 3.02 ? i have done this using 3.02 and `LoginButton` – Shoshi Mar 05 '13 at 19:45
  • I am. And they were on the same page like above? – baconcheese113 Mar 05 '13 at 20:05
0

For anyone that is wondering about the second part of my question:

To reopen a Facebook session using the Facebook SDK use this code

if(Session.openActiveSession(this) == null) { //Haven't logged in yet
    openSessionForRead(getString(R.string.app_id), Arrays.asList("email"));
}

Facebook caches the token.

baconcheese113
  • 843
  • 2
  • 13
  • 27