android facebook how to add permission - android

I want to add permission to get the email of the user, i am using this code
Session.openActiveSession(this, true, new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state,
Exception exception) {
// TODO Auto-generated method stub
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
et_firstName.setText(user
.getFirstName());
et_lastName.setText(user
.getLastName());
Log.e("email",
user.asMap().get("email")
+ "");
} else {
}
}
});
}
}
});
break;
I have tried googleing alot alot but all they talk about loginbutton but i don't want to use loginbutton,
any help would be appreciated

Download SDK http://developers.facebook.com/android/ and read docs...

Related

Getting null email address in facebook sdk integration

Using facebook sdk version 3.0 & following is my code.I have getting id and name value but null email address every time.
authButton.setReadPermissions(Arrays.asList("basic_info","email"));
// session state call back event
authButton.setSessionStatusCallback(new
Session.StatusCallback() {
#Override
public void call(Session session,
SessionState state,
Exception exception) {
if (session.isOpened()) {
Log.i(TAG,"Access Token"+ session.getAccessToken());
Request.newMeRequest(session,
new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user,Response response) {
if (user != null) {
Log.i(TAG,"User ID "+ user.getId());
Log.i(TAG,"Email "+ user.asMap().get("email"));
}
}
}).executeAsync();
}
}
});
No need set Permissions as seperate for reading
Session.OpenRequest openRequest = new Session.OpenRequest(LandingPageActivity.this);
openRequest.setPermissions(Arrays.asList...);
openRequest.setCallback(new Session.StatusCallback() {
// callback when session changes state
#Override
public void call(Session session, SessionState state,
Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request request = Request.newMeRequest(session,
new Request.GraphUserCallback() {
// callback after Graph API response with user
// object
#Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
string email= user.getProperty("email");
}
}
});
request.executeAsync();
}
});
Session session = new Session(LandingPageActivity.this);
Session.setActiveSession(session);
session.openForRead(openRequest);
Reference : click Here

android facebook sdk - set permissions for openActiveSession

I am trying to integrate Facebook SDK to an android app. I got the code from Facebook manual. It uses Session.openActiveSession and then request a graph user. How could I request for more permissions without using LoginButton class?
Session.openActiveSession(this, true, new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
onSessionStateChange(session, state, exception);
if (session.isOpened()) {
Request.executeMeRequestAsync(session, new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
// got user graph
} else {
// could not get user graph
}
}
});
}
}
});
Thank you.
Try this:
mCallback = new Session.StatusCallback() {...}; // the code you already have
Session.OpenRequest request = new Session.OpenRequest(mContext);
request.setPermissions(Arrays.asList("email", "user_birthday"));
request.setCallback(mCallback );
// get active session
Session mFacebookSession = Session.getActiveSession();
if (mFacebookSession == null || mFacebookSession.isClosed())
{
mFacebookSession = new Session(mContext);
Session.setActiveSession(mFacebookSession);
}
mFacebookSession.openForRead(request);
This solves the problem using opensession and extended persmission just once. Facebook SDK 3.5
Session s = new Session(this);
Session.setActiveSession(s);
Session.OpenRequest request = new Session.OpenRequest(this);
request.setPermissions(Arrays.asList("basic_info","email"));
request.setCallback( new Session.StatusCallback() {
// callback when session changes state
#Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Request.newMeRequest(session, new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user, Response response) {
if (user != null) {
Toast.makeText(getApplicationContext(), "User email is:"+user.getProperty("email"), Toast.LENGTH_SHORT).show(); }
else {
Toast.makeText(getApplicationContext(), "Error User Null", Toast.LENGTH_SHORT).show();
}
}
}).executeAsync();
}
}
}); //end of call;
s.openForRead(request); //now do the request above

Get user ID and Email using Facebook SDK Android

I am trying to get the logged in user's id and email. Here is my code:
authButton.setReadPermissions(Arrays.asList("basic_info","email"));
// session state call back event
authButton.setSessionStatusCallback(new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state, Exception exception) {
if (session.isOpened()) {
Log.i(TAG,"Access Token"+ session.getAccessToken());
Request.newMeRequest(session,
new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user,Response response) {
if (response != null) {
Log.i(TAG,"User ID "+ user.getId());
Log.i(TAG,"Email "+ user.asMap().get("email"));
}
}
});
}
}
});
Everything goes ok till here
Log.i(TAG,"Access Token"+ session.getAccessToken());
I can see the access token, but the onComplete method is not called, and i don't get any user info.
what am i doing wrong?
Try
if (user != null)
instead of
if (response != null)
or try
Request.newMeRequest(...).executeAsync();

android how to add permission to facebook

i want to add permission to read email from the facebook android sdk.
code
Session.openActiveSession(this, true, new Session.StatusCallback() {
#Override
public void call(Session session, SessionState state,
Exception exception) {
// TODO Auto-generated method stub
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
#Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
et_firstName.setText(user
.getFirstName());
et_lastName.setText(user
.getLastName());
Log.e("data",
user.asMap().get("email")
+ "");
URL image_value;
try {
image_value = new URL(
"http://graph.facebook.com/"
+ user.getId()
+ "/picture");
iv_profileImage
.setImageBitmap(BitmapFactory
.decodeStream(image_value
.openConnection()
.getInputStream()));
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} else {
}
}
});
}
}
});
what i have tried
I read a lot that this can be done using loginbutton but i don't want to use loginbutton.
also i read that if i don't want to use logingbutton, i have to use openfor session, but i didn't know how to use that
please help me, i have been trying for it for like a week
If you use a LoginButton, use:
loginButton.setReadPermissions(Arrays.asList("email"));
If you start the Session yourself, use:
session.openForRead(new Session.OpenRequest(this).setPermissions(Arrays.asList("email")));
requests/permissions helpfull link: https://developers.facebook.com/tools/explorer/
After successfull login, try the request again including the email field.

How to give Facebook permission for accessing user data in facebook-sdk-3.0

I'm developing an application in which I'm using Facebook login for authentication and stuff. facebook sdk 3.0 needs some permission for accessing user data such as profile picture, emailID,publish_stram and etc. How to give permission in the code for accessing those things. Till now I'm able to get fb_access_token. Here is my code:
Session.openActiveSession(this, true, new Session.StatusCallback() {
// callback when session changes state
#Override
public void call(Session session, SessionState state,
Exception exception) {
if (session.isOpened()) {
// make request to the /me API
Request.executeMeRequestAsync(session,
new Request.GraphUserCallback() {
// callback after Graph API response with
// user
// object
#Override
public void onCompleted(GraphUser user,
Response response) {
if (user != null) {
fb_user_id = user.getId();
}
Session session = Session
.getActiveSession();
if (session.isOpened()) {
access_token = session
.getAccessToken();
}
new postFBData().execute();
}
});
}
}
});
Taken this code snippet from Facebook samples. How to give permission before accessing access_token from FB?
Any help will be appreciated.
Calling Session.openActiveSession will only give you basic permissions (until you've requested additional ones). You also need to separate the read and publish permission requests.
In your case, I would do something like:
Session session = // create a new Session using Session.Builder
Session.OpenRequest openRequest = // create an OpenRequest using Session.OpenRequest
openRequest.setPermissions( READ_PERMISSION_LIST );
session.openForRead(openRequest);
Session.setActiveSession(session);
Then, once you've opened the session,
// check if you already have publish permissions first
if (!Session.getActiveSession.getPermissions.contains("publish_stream")) {
Session.NewPermissionsRequest permissionRequest = // create a NewPermissionsRequest
permissionRequest.setPermissions( PUBLISH_PERMISSION_LIST);
Session.getActiveSession().requestNewPublishPermissions(permissionRequest);
}
i think this is how you authorize a certain kind of functionality in the String[]
fb.authorize(MainActivity.this,new String[] {"publish_stream"}, new DialogListener(){
#Override
public void onFacebookError(FacebookError e)
{
Toast.makeText(MainActivity.this, "on Facebook error", Toast.LENGTH_SHORT).show();
}
#Override
public void onError(DialogError e)
{
Toast.makeText(MainActivity.this, "on error", Toast.LENGTH_SHORT).show();
}
#Override
public void onComplete(Bundle values)
{
updateButtonImage();
}
#Override
public void onCancel()
{
}
});

Categories

Resources