Note that there are some explanatory texts on larger screens.

plurals
  1. POTrouble with accessing friends using Facebook-Android SDK
    primarykey
    data
    text
    <p>I have been struggling with android and the Facebook's graph API and I'm sure this is a piece of cake for intermediate programmers. What I want is a very simple Android application that logs in a user to Facebook, get the users consent to access information and finally to <strong>seamlessly</strong> query the graph API to get the users friends. I mention the work seamless because I have seen many sample applications that require the user to push a "get friends" button but I do not want that. I wish to extract the users friends without requiring him to push anything.</p> <p>I have pasted the code below. I am able to to log-in and grant permission to my application. Next, I expect it to display my friends but it just directs me to a blank page. The problem might be that I am accessing the graph API in the wrong place because <strong>the Logcat does not contain the messages I print before and after the request</strong>. Could you please help me. </p> <p>public class FacebookLogin extends Activity {</p> <pre><code>Facebook mFacebook = new Facebook("XXXXXXXXXXXX"); AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(mFacebook); View linearLayout; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); linearLayout = findViewById(R.id.main_layout); mFacebook.authorize(this, new DialogListener() { @Override public void onComplete(Bundle values) { Log.d("Facebook-Example-Friends Request", "Started API request"); mAsyncRunner.request("me/friends", new FriendsRequestListener()); Log.d("Facebook-Example-Friends Request", "Finished API request"); } @Override public void onFacebookError(FacebookError error) {} @Override public void onError(DialogError e) {} @Override public void onCancel() {} }); } @Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); mFacebook.authorizeCallback(requestCode, resultCode, data); } public class FriendsRequestListener implements RequestListener { /** * Called when the request to get friends has been completed. * Retrieve, parse and display the JSON stream. */ public void onComplete(final String response) { Log.d("Facebook-Example-Friends Request", "FriendsListenerOnComplete"); try { JSONObject json = Util.parseJson(response); final JSONArray friends = json.getJSONArray("data"); FacebookLogin.this.runOnUiThread(new Runnable() { public void run() { int l = (friends != null ? friends.length() : 0); for (int i=0; i&lt;l; i++) { try { JSONObject o = friends.getJSONObject(i); TextView tv = new TextView(FacebookLogin.this); tv.setText(o.getString("name")); ((LinearLayout) linearLayout).addView(tv); } catch(JSONException e) { Toast.makeText(getApplicationContext(), "JSON parsing error", Toast.LENGTH_LONG); } } } }); } catch(JSONException e) { Log.d("Facebook-Example-Friends Request", "JSON Error in response"); } catch(FacebookError e) { Log.d("Facebook-Example-Friends Request", "Facebook Error in response"); } } } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload