0

Possible Duplicate:
launch facebook app from other app

I am doing one android project, In that project i need to get Facebook User Details like UserId,AccessToken.

Done Facebook Integration using Fcebook SDK.

Now, Facebook Released URL SCHEME to open facebook application and get user details.

I'm Done like this,

long longFacebookUid = Long.parseLong(facebookUid);
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setClassName("com.facebook.katana", "com.facebook.katana.ProfileTabHostActivity");
intent.putExtra("extra_user_id", facebookUid);
this.startActivity(intent);
return;

In this code Called Facebook Application, After that i don't no How to get userId and Token.

Thanks.

Community
  • 1
  • 1
Jeeva123
  • 1,047
  • 3
  • 20
  • 34

1 Answers1

0

Beside URL SCHEME, using the SDK based function is more simple.But it may not be the answer you want.

Remarks: The following information is based on facebook-android SDK 2.0(3.0 is avaliable now)

After running the authorize function (Login Part)(The following is sample code in facebook document)

 facebook.authorize(this, new String[] {}, new DialogListener() {
            @Override
            public void onComplete(Bundle values) {
                SharedPreferences.Editor editor = mPrefs.edit();
                editor.putString("access_token", facebook.getAccessToken());
                editor.putLong("access_expires", facebook.getAccessExpires());
                editor.commit();
            }

            @Override
            public void onFacebookError(FacebookError error) {}

            @Override
            public void onError(DialogError e) {}

            @Override
            public void onCancel() {}
        });
    }

In order to get the access token, just run the following function in SDK 2.0

String access_token=facebook.getAccessToken();

For the userID

public String GetUserID(){
    Bundle params = new Bundle();
    params.putString("fields", "id");
    String resp= "";
    try {
        resp = facebook.request("me", params, "GET");//call the request function in SDK 2.0, using graph api
    } catch (FileNotFoundException e) {
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    }
    try{
        resp = new JSONObject(resp).getString("id");
    }catch(JSONException e1){
    }
    }
    return resp;
};

I think these are the most simply way to get the result, but not using the URL SCHEME.

I hope it can help you.

L.C. Echo Chan
  • 586
  • 12
  • 29