Does the Facebook SDK only support actions?

I am trying to implement the Facebook SDK in my application so that users can post to our fan club through the application. However, I could not even register the user through the SDK.

In the SDK examples, a simple sample was provided that uses Activity to try to authorize a user using Single Sign-On. I tried this example myself and it works. I can log in, I had to authorize the application in order to use my data on Facebook, and I could see that requests are being executed and accepted in LogCat.

Now I tried to add the same code to my application. This Fragment application is based on the Compatibility package. There is one central FragmentActivity , and the rest of my classes are simple Fragments . When you add an example code to one of these Fragments , the Facebook application starts for half a second when you try to log in, but then it closes and nothing happens. I returned to my usual fragment again.

When checking LogCat after that, it says nothing that the Facebook application even opened or made any requests, except for the fact that it shows some print checks that I added, and the fact that it says that it starts the Facebook intent :

 01-12 13:19:40.874: I/System.out(6087): Calling authorize 01-12 13:19:40.874: I/ActivityManager(1380): Starting activity: Intent { cmp=com.facebook.katana/.ProxyAuth (has extras) } from pid 6087 01-12 13:19:40.874: I/System.out(6087): Called authorize 

Other than that, nothing returns. There are no Facebook checks, no allegations that my keys are incorrect or something else, just nothing. The goal of Facebook was triggered, but closed almost immediately, and nothing else shows that it was even open.

It made me think for a few hours, and I'm starting to think that the usual, selective approach just doesn't work in Fragments due to the work of Fragments .

The code I used is posted below. The fragment is launched by a button that calls FragmentTransaction . Am I doing something fundamentally wrong here, or is the Facebook SDK really not working with Fragments ? I tried to find this problem, but I could not find someone else with the same situation.


 public class FanWallFacebook extends Fragment { Facebook facebook = new Facebook("294678133912628"); public FanWallFacebook() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment return inflater.inflate(R.layout.filler, container, false); } @Override public void onStart() { super.onStart(); System.out.println("Calling authorize"); facebook.authorize(getActivity(), new DialogListener() { @Override public void onComplete(Bundle values) { System.out.println("Completed"); } @Override public void onFacebookError(FacebookError error) { System.out.println("Facebook error: "+error.getMessage()); } @Override public void onError(DialogError e) { System.out.println("General error: "+e.getMessage()); } @Override public void onCancel() { System.out.println("Cancelled"); } }); System.out.println("Called authorize"); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); facebook.authorizeCallback(requestCode, resultCode, data); System.out.println("Authorize callback'd"); } } 

Edit

Just tried using FragmentActivity , and there it works. He successfully logs into the system. It seems that the SDK really only works with classes that explicitly extend ...Activity . Can someone give me an idea why this could be so? I always thought that Fragments is somewhere along the line extended by Activity .

+4
source share
2 answers

I ended up using FragmentActivity for my interaction with Facebook. Not an ideal solution, but it works.

0
source

Well...

The new Facebook SDK has an action that implements FragmentActivity so that the problem is resolved.

0
source

Source: https://habr.com/ru/post/1390634/


All Articles