just trying to allow my app to access basic information from an authenticated Facebook user, yet my logcat tells me
06-30 16:37:27.969: WARN/System.err(1559): com.facebook.android.FacebookError: An active access token must be used to query information about the current user.
right after authentification where the code is ran. Can someone point me in the right direction? I’ve seen a very similar post where someone used almost identical code and It worked.
Thanks
Facebook facebook = new Facebook("187212574660004");
TextView nText;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
nText = (TextView) this.findViewById(R.id.nameText);
facebook.authorize(this, new String[] {"offline_access", "user_interests", "friends_interests"},
new DialogListener() {
public void onComplete(Bundle values) {
setContentView(R.layout.homepage);
}
public void onFacebookError(FacebookError error) {}
public void onError(DialogError e) {}
public void onCancel() {}
});
JSONObject json_data = null;
try
{
JSONObject response = Util.parseJson(facebook.request("me/friends")); // Get a friend information from facebook
JSONArray jArray = response.getJSONArray("data");
json_data = jArray.getJSONObject(0);
String name = json_data.getString("name");
Log.i("friend is", name);
nText.setText(name);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (JSONException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
catch (FacebookError e)
{
e.printStackTrace();
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
}
Tried the method as described before by Manno23 and got
06-30 19:27:04.338: ERROR/AndroidRuntime(349): Caused by: java.lang.NullPointerException
06-30 19:27:04.338: ERROR/AndroidRuntime(349): at com.staffit.FacebookPage.getFriends(FacebookPage.java:67)
06-30 19:27:04.338: ERROR/AndroidRuntime(349): at com.staffit.FacebookPage.access$0(FacebookPage.java:55)
06-30 19:27:04.338: ERROR/AndroidRuntime(349): at com.staffit.FacebookPage$1.onComplete(FacebookPage.java:41)
06-30 19:27:04.338: ERROR/AndroidRuntime(349): at com.facebook.android.Facebook.authorizeCallback(Facebook.java:383)
06-30 19:27:04.338: ERROR/AndroidRuntime(349): at com.staffit.FacebookPage.onActivityResult(FacebookPage.java:93)
06-30 19:27:04.338: ERROR/AndroidRuntime(349): at android.app.Activity.dispatchActivityResult(Activity.java:3907)
06-30 19:27:04.338: ERROR/AndroidRuntime(349): at android.app.ActivityThread.deliverResults(ActivityThread.java:2492)
06-30 19:27:04.338: ERROR/AndroidRuntime(349): ... 11 more
Both of the above answers are correct. You can just put the chunk of code that does the request into a separate method and call that method in onComplete(), i.e.