My App logs into facebook but when I check the token it returns this error: {accessToken token: ACCESS_TOKEN_REMOVED permissions: [user_friends, contact_email, email, public_profile]}.
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
callbackManager = CallbackManager.Factory.create();
View view = inflater.inflate(R.layout.login, container, false);
authButton = (LoginButton)view.findViewById(R.id.authButton);
authButton.setFragment(this);
authButton.setReadPermissions(Arrays.asList("email"));
progress = (ProgressBar) view.findViewById(R.id.progressBar);
progress.setVisibility(View.INVISIBLE);
editEmail = (EditText) view.findViewById(R.id.editEmail);
editSenha = (EditText) view.findViewById(R.id.editSenha);
LoginManager.getInstance().registerCallback(callbackManager,
new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
AccessToken accessToken = loginResult.getAccessToken();
MyLog.log("Logged in!...");
makeMeRequest(loginResult);
}
#Override
public void onCancel() {
MyLog.log("Logged out...");
progress.setVisibility(View.INVISIBLE);
}
#Override
public void onError(FacebookException exception) {
MyLog.log("Logged out...");
progress.setVisibility(View.INVISIBLE);
}
});
return view;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
Can someone help me?
Related
I have been trying to integrate Facebook login with Android, login to facebook happens, however I am not getting a callback in onActivityResult. I have already followed this:
Facebook Login CallbackManager FacebookCallback not called?
However, my problem remains unsolved. Here is a code snippet:
#Override
protected FragmentPresenter getFragmentPresenter() {
return presenter;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(getLayoutId(), container, false);
setHasOptionsMenu(true);
view.setClickable(true);
setupView(view);
//FacebookSdk.sdkInitialize(FacebookSdk.getApplicationContext());
FacebookSdk.sdkInitialize(getContext());
callbackManager = CallbackManager.Factory.create();
loginFacebook.setReadPermissions(Arrays.asList(EMAIL));
loginFacebook.setFragment(this);
loginFacebook.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
getActivity().setResult(RESULT_OK);
getActivity().finish();
}
#Override
public void onCancel() {
getActivity().setResult(RESULT_CANCELED);
getActivity().finish();
}
#Override
public void onError(FacebookException exception) {
//Handle Exception
}
});
return view;
}
Please help me.
I use fragment for facebook login. Normally everything goes fine. But in first time , when user login with facebook s/he redirected to facebook page and give permission to program but then (despite i use CallbackManager.onActivityResult) , program cannot handle the callback and stay background. How can i handle the callback ??
Relative code snippet:
public void onCreate(Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
super.onCreate(savedInstanceState);
callbackManager = CallbackManager.Factory.create();
}
public void onResume() {
Log.i("tago" , "onResume");
super.onResume();
Profile profile = Profile.getCurrentProfile();
if (profile != null) {
tumisim = profile.getName();
firstname = profile.getFirstName();
lastname = profile.getLastName();
sharedtumisimkaydet(tumisim);
sharedfirstnamekaydet(firstname);
sharedlastnamekaydet(lastname);
}
}
public void onStop() {
super.onStop();
getActivity().finish();
}
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.facebookfragment, container, false);
int[] taniticiresimler = {R.mipmap.aciklama,R.mipmap.dene_uc,R.mipmap.yenigus,R.mipmap.galp};
CustomPagerAdapter pagerAdapter = new CustomPagerAdapter(getActivity(),taniticiresimler);
FadingIndicator indicator = (FadingIndicator)view.findViewById(R.id.circleIndicator);
ViewPager viewPager = (ViewPager) view.findViewById(R.id.pager);
viewPager.setAdapter(pagerAdapter);
indicator.setViewPager(viewPager);
indicator.setFillColor(Color.BLUE);
indicator.setStrokeColor(Color.BLACK);
indicator.setRadius(15f);
LoginButton loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setReadPermissions(Arrays.asList("user_friends", "public_profile", "email"));
loginButton.setFragment(this);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
profile = Profile.getCurrentProfile();
if (profile.getId() != null) {
facebookID = profile.getId();
String a = sharedFacebookIDAl();
if (a.equals("defaultfacebookID")) {
sharedilkgiriskaydet(true);
}else if(!a.equals(facebookID)){
sharedilkgiriskaydet(true);
}else{
sharedilkgiriskaydet(false);
}
sharedfacebookIDkaydet(facebookID);
KullaniciProfilCek kPC = new KullaniciProfilCek();
kPC.execute(profile.getId());
}
GraphRequest request = GraphRequest.newMeRequest(AccessToken.getCurrentAccessToken(),
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
try {
email = object.getString("email");
sharedemailkaydet(email);
cinsiyet = object.getString("gender");
sharedcinsiyetkaydet(cinsiyet);
coverphotourl = object.getJSONObject("cover").getString("source");
sharedcoverphotourlkaydet(coverphotourl);
} catch (JSONException e) {
e.printStackTrace();
}
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "email,gender,cover");
request.setParameters(parameters);
request.executeAsync();
}
#Override
public void onCancel() {
Toast.makeText(getActivity(), "Facebook Login iptal edildi", Toast.LENGTH_LONG).show();
}
#Override
public void onError(FacebookException error) {
Toast.makeText(getActivity(), "Facebook Login hata oluşturdu", Toast.LENGTH_LONG).show();
}
});
return view;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
Log.i("tago" , "geri geldi");
}
Inside the fragment you cannot listen onActivityResult directly. Listen the results in the onActivityResult inside your Activity. Put the code below in the Activity which holds the fragment.
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
super.onActivityResult(requestCode, resultCode, intent);
Fragment fragment = (Fragment) getChildFragmentManager().findFragmentByTag(childTag);
if (fragment != null) {
fragment.onActivityResult(requestCode, resultCode, intent);
}
}
and then the OnActivityResult() inside the fragment will work.
You are using onActivityResult() wrong - you do not call super class implementation unless you know you need to. This got nothing with the need of calling super i.e. in onCreate() etc. Here's documentation you should read now:
https://developer.android.com/training/basics/intents/result.html
When I sign in facebook, my callback is not working.
I do not know why this part is not working: loginButton.registerCallback(callbackManager...
This is my code:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return initView(inflater, container);
}
private View initView(LayoutInflater inflater, ViewGroup container) {
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
callbackManager = CallbackManager.Factory.create();
Log.d("FB","1");
final View view = inflater.inflate(R.layout.fragment_login, container, false);
name=(TextView)view.findViewById(R.id.FBname);
link=(TextView)view.findViewById(R.id.FBlink);
id=(TextView)view.findViewById(R.id.FBid);
LoginButton loginButton = (LoginButton)view.findViewById(R.id.login_button);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {
accessToken = loginResult.getAccessToken();
Log.d("FB","access token got.");
//send request and call graph api
GraphRequest request = GraphRequest.newMeRequest(
accessToken,
new GraphRequest.GraphJSONObjectCallback() {
#Override
public void onCompleted(JSONObject object, GraphResponse response) {
Log.d("FB","complete");
Log.d("FB",object.optString("name"));
name.setText("name:" + object.optString("name"));
Log.d("FB", object.optString("link"));
link.setText("link:"+object.optString("link"));
Log.d("FB", object.optString("id"));
id.setText("id:"+object.optString("id"));
}
});
Bundle parameters = new Bundle();
parameters.putString("fields", "id,name,link");
request.setParameters(parameters);
request.executeAsync();
}
#Override
public void onCancel() {
// App code
Log.d("FB", "CANCEL");
}
#Override
public void onError(FacebookException exception) {
// App code
Log.d("FB",exception.toString());
}
});
return view;
}
Thanks for all respondents
did you added this to your activity?
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
Im trying to log in with facebook on my application, but when I click the login button it opens a window saying "not logged in"
I am recieve these two errors
E/DataReductionProxySettingListener: No DRP key due to exception:java.lang.ClassNotFoundException: com.android.webview.chromium.Drp
E/SysUtils: ApplicationContext is null in ApplicationStatus
Here is my code:
public class fragment_fb_btn extends Fragment {
...
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FacebookSdk.sdkInitialize(getActivity().getApplicationContext());
callbackManager = CallbackManager.Factory.create();
View view = inflater.inflate(R.layout.fragment_fb_btn, container, false);
loginButton = (LoginButton) view.findViewById(R.id.login_button);
loginButton.setReadPermissions("user_friends");
loginButton.setFragment(this);
loginButton.registerCallback(callbackManager, new FacebookCallback<LoginResult>() {
#Override
public void onSuccess(LoginResult loginResult) {}
#Override
public void onCancel() {}
#Override
public void onError(FacebookException exception) {}
});
return view;
}
#Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
Thanks, if anyone could tell me how to fix this I would be very happy
I am sharing a video on FB via share dialog in Android. The sharing works perfectly fine. However, FB post id returns null. The callback returns even before the video is uploaded. Please let me know, if I missing something. Below is my code.
public class TestFragment extends Fragment {
private CallbackManager callbackManager;
private ShareDialog shareDialog;
public TestFragment() {
// Required empty public constructor
}
public static TestFragment newInstance(String path, String json) {
TestFragment fragment = new TestFragment();
return fragment;
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getActivity());
callbackManager = CallbackManager.Factory.create();
shareDialog = new ShareDialog(this);
// this part is optional
shareDialog.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Timber.d("result.getPostId() :: " + result.getPostId());
}
#Override
public void onCancel() {
Timber.d("Facebook : Cancelled");
}
#Override
public void onError(FacebookException e) {
Timber.d(e.getMessage());
}
});
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_test, container, false);
ButterKnife.inject(this, view);
return view;
}
#OnClick(R.id.facebookShare)
public void share() {
Timber.d("share button pressed");
if (ShareDialog.canShow(ShareVideoContent.class)) {
Timber.d("showing share dialog");
shareDialog.show(getVideoContent());
} else {
Timber.d("unable to show the share dialog");
}
}
private ShareVideoContent getVideoContent() {
Timber.d(mVideoMetadata.getVideoId());
ShareVideo shareVideo = new ShareVideo.Builder()
.setLocalUrl(Uri.parse("... file ..."))
.build();
ShareVideoContent content = new ShareVideoContent.Builder()
.setVideo(shareVideo)
.build();
return content;
}
#Override
public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
shareDialog.show(shareContent, ShareDialog.Mode.FEED);
Set mode to ShareDialog.Mode.FEED.
It's working for me .
Here's example
When Login Success With Facebook Then Call This Method
shareOnFacebook()
private void shareOnFacebook(){
ShareLinkContent shareContent = new ShareLinkContent.Builder()
.setContentTitle("The Simpson!")
.setContentUrl(Uri.parse("http://www.codecube.in/airbucks-project"))
.build();
mFacebookShareDialog.show(shareContent, ShareDialog.Mode.FEED);
mFacebookShareDialog.registerCallback( this.callbackManager, new FacebookCallback<Sharer.Result>() {
#Override
public void onSuccess(Sharer.Result result) {
Log.v("MyApp", "Share success!"); //Showed if I press the share or the cancel button
String postID = result.getPostId();
Log.v("MyApp", "Share success!" +result.getPostId());
}
#Override
public void onCancel() {
Log.v("MyApp", "Share canceled"); //Only showed when I press the close button
}
#Override
public void onError(FacebookException e) {
Log.v("MyApp","Share error: " + e.toString());
}
});
mFacebookShareDialog.show(shareContent, ShareDialog.Mode.FEED);
}
#Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}