When we post image on facebook by my android app it's post successfully but when we click on that post on Facebook app (on mobile devices) there is a toast appear "There's a problem opening this app." but when open in WEB and click on that posted image it'll redirect to shared link successfully.
I have use this code to share post on facebook.
GraphRequest request = GraphRequest.newPostRequest(AccessToken.getCurrentAccessToken(),
"me/feed", null, new GraphRequest.Callback() {
#Override
public void onCompleted(GraphResponse response) {
Log.i(TAG, response.toString());
//checkPostStatusAndEnableButton();
}
});
Bundle postParams = request.getParameters();
postParams.putString("link",post_url);
postParams.putString("caption", caption);
request.setParameters(postParams);
request.executeAsync();
Is we have use some other action for url for mobile devices?
Try this on :
private static List<String> PERMISSIONS = Arrays.asList("public_profile","user_photos","user_videos", "email","user_likes","user_posts",
"user_hometown", "user_location","user_about_me","user_birthday",
"user_friends","user_relationship_details");
LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
// App code
Log.i(TAG,"onSuccess registerCallback");
}
#Override
public void onCancel() {
// App code
Log.i(TAG,"onCancel registerCallback");
}
#Override
public void onError(FacebookException exception) {
// App code
Log.i(TAG,"onError registerCallback");
}
});
Then call this share link method :
private void shareLink() {
ShareLinkContent content = new ShareLinkContent.Builder()
.setContentUrl(Uri.parse("https://developers.facebook.com"))
.build();
ShareDialog shareDialog = new ShareDialog(this);
shareDialog.show(content, ShareDialog.Mode.AUTOMATIC);
}
Related
I am logging into facebook on Android using facebook android sdk (4.7.0). Most of the time it shows following dialog and works fine.
But sometimes it shows the following dialog and login does not work.
What are possibilites for failed login in this case? I am testing it on android (5.1.1).
facebookButton.setReadPermissions(Arrays.asList("public_profile, email, user_birthday"));
callbackManager = CallbackManager.Factory.create();
facebookButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(
JSONObject object,
GraphResponse response) {
// Application code
try {
fbid = object.getString("id");
fbfirst_name = object.getString("first_name");
fblast_name = object.getString("last_name");
fbemail = object.getString("email");
new FBRegistrationService().execute();
} catch (Exception ex) {
ex.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,email,gender,birthday,first_name,last_name");
request.setParameters(parameters);
request.executeAsync();
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException exception) {
}
});
Update: I am also getting these logs.
"Blink deferred a task in order to make scrolling smoother. Your timer and network tasks should take less than 50ms to run to avoid this. Please see https://developers.google.com/web/tools/chrome-devtools/profile/evaluate-performance/rail and https://crbug.com/574343#c40 for more information.", source: https://m.facebook.com/login.php?skip_api_login=1&api_key=350893648453711&signed_next=1&next=https%3A%2F%2Fm.facebook.com%2Fv2
I have been using the Facebook SDK for Android a bit now. I have been having trouble where one of my testers could not create an account in my app using Facebook. After some debugging I figured out that for some reason when he tries to login / register the JSON object that contains the information does not come with his email. This only happens for HIS account!
Does anyone know why this could happen?
(I have included a simplified version of my login code so you can see if there is anything wrong with it that might cause it)
List<String> permissionNeeds = Arrays.asList("public_profile", "user_friends", "email");
loginButton.setReadPermissions(permissionNeeds);
loginButton.registerCallback(mCallbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(final LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(
loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
Log.d(TAG, object.toString()); // Has no email sometimes!
} catch (JSONException e) {
e.printStackTrace();
Log.e(TAG, String.format("Error with facebook login: %s", e.getMessage()));
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,picture,email,gender");
request.setParameters(parameters);
request.executeAsync();
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException error) {
Log.d(TAG, String.format("Error with facebook login: %s", error.getMessage()));
}
});
loginButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
LoginManager.getInstance().logInWithReadPermissions(SplashActivity.this,
Arrays.asList("public_profile", "user_friends", "email"));
}
});
If any more information is needed, please tell me I'll be happy to add some.
Thanks!
So turns out that my tester had an inactive email account.
In general you should never be counting on every Facebook user having an email address.
I am doing simple facebook login using latest facebook sdk 4.8 but after login i am getting null value no user details are coming but only i am getting the details if the user is developer and administrator of that Facebook App.
And also i have given facebook permission.
loginButton.setReadPermissions(Arrays.asList("public_profile", "user_likes",
"user_friends", "email", "user_birthday", "user_photos", "user_about_me"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(final LoginResult loginResult) {
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
try{
nameTxt.setVisibility(View.VISIBLE);
nameTxt.setText(jsonObject.getString("name"));
}catch(Exception e){
e.printStackTrace();
Log.d("FacebookException", e.toString());
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link,gender,birthday,email,bio,photos{link}");
request.setParameters(parameters);
request.executeAsync();
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException e) {
}
});
Have you switched your app status to live? You can see status in your app's Dashboard in developers console.
If not, just switch status to live in Status & Review tab. This switch should be switched to 'Yes' position
I'm using the new Facebook SDK and making the following request:
GraphRequest request = GraphRequest.newMeRequest(mLoginResult.getAccessToken(),
new GraphRequest.GraphJSONObjectCallback(){
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
Profile userProfile = Profile.getCurrentProfile();
FacebookUser user = new FacebookUser(userProfile, object.optString("email"));
sendUserInfo(user);
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "email");
request.setParameters(parameters);
request.executeAsync();
The email is not being returned, here is my LoginManager's callback:
LoginManager.getInstance().registerCallback(mFacebookCallbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
mLoginResult = loginResult;
}
#Override
public void onCancel() {
}
#Override
public void onError(FacebookException exception) {
}
});
What am I doing wrong? If I remove the request parameters, everything but the email is returned.
In my case, somehow my email wasn't being returned even in Graph Explorer. So I had to add an alternative email, make it my default and everything worked perfectly!
I'm developing new android app which uses facebook sdk. I want to fetch users friends list, I'm doing it like that:
Request request = Request.newMyFriendsRequest(
Session.getActiveSession(),
new Request.GraphUserListCallback() {
public void onCompleted(List<GraphUser> paramAnonymousList,
Response paramAnonymousResponse) {
Toast.makeText(getApplicationContext(),
paramAnonymousList.toString(),
Toast.LENGTH_SHORT).show();
Log.e(TAG, paramAnonymousList.toString()
+ paramAnonymousResponse.toString());
}
});
request.executeAsync();
However when I run app I'm getting something like that:
GraphObjectList{itemType=GraphUser, state=[]}{Response: responseCode: 200, graphObject: GraphObject{graphObjectClass=GraphObject, state={"data":[]}}, error: null, isFromCache:false}
I tried to run this code inside app which is not in development mode and it's working fine - i'm able to fetch user's data. What can be the cause of response code 200. According to that: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.0 response code 200 belong to facebook permission errors. But to fetch user's friends list I don't have to provide any specific permissions, so what can be the cause of this response?
Thanks in advance
HTTP 200 means that your request is OK.
The real issue is Facebook API v2.0. Apps cannot retrieve the full list of friends for a user, only friends already using the application. Even if you application is still in v1.0, users who first logged in after May 1st are getting v2.0 behaviour.
Reference: https://developers.facebook.com/docs/graph-api/reference/v2.0/user/friends
Cheers!
I have done in this way and works fine perfectly in Facebook SDK 4.18.0
public class SignIn extends AppCompatActivity {
CallbackManager callbackManager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//before set conteview
FacebookSdk.sdkInitialize(getApplicationContext());
// AppEventsLogger.activateApp(this);
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_signin);
LoginButton loginButton = (LoginButton) findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("public_profile", "email"));
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
GraphRequest graphRequest=GraphRequest.newMeRequest(loginResult.getAccessToken(), new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject jsonObject, GraphResponse graphResponse) {
Log.d("Graph Response",graphResponse.toString());
String myCustomizedResponse = graphResponse.getJSONObject().toString();
Log.d("Ketan_Ramani",graphResponse.getJSONObject().toString());
try {
JSONObject obj = new JSONObject(myCustomizedResponse);
String id = obj.getString("id");
String first_name = obj.getString("first_name");
String last_name = obj.getString("last_name");
String email = obj.getString("email");
Log.d("Id",id);
Log.d("FirstName",first_name);
Log.d("LastName",last_name);
Log.d("Email",email);
} catch (JSONException e) {
Utils.hide_dialog();
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,first_name,last_name,email");
graphRequest.setParameters(parameters);
graphRequest.executeAsync();
}
#Override
public void onCancel() {
// App code
}
#Override
public void onError(FacebookException exception) {
// App code
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}