At the oficial facebook developers tutorial, they say posting in users Wall on facebook is as easy as writing this single line:
mFacebook.dialog(context, "feed", new PostDialogListener());
but when I try to use this, it keeps asking me to create the PostDialogListener class. Isn't that included with facebook sdk? where can I find this class?
and, to logout, I must use this:
mAsyncRunner.logout(getContext(), new RequestListener() {
@Override
public void onComplete(String response, Object state) {}
@Override
public void onIOException(IOException e, Object state) {}
@Override
public void onFileNotFoundException(FileNotFoundException e,
Object state) {}
@Override
public void onMalformedURLException(MalformedURLException e,
Object state) {}
@Override
public void onFacebookError(FacebookError e, Object state) {}
});
And then I'm asked to create getContext() method.
Facebook's tutorial is very incomplete, what must I do now? Thanks!
Edit: My facebook activity is very simple, i just connect and retrieve data from user, then pass it to another activity. I wat to implement a logout method, and also ask user to post on wall after login (that would be in another activity)
public class FacebookConnectActivity extends Activity {
private static final String TAG_JSON = "json";
Facebook facebook = new Facebook("12121212112");
AsyncFacebookRunner mAsyncRunner;
private SharedPreferences mPrefs;
JSONObject json;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.resgatar_produto_layout);
mPrefs = getPreferences(MODE_PRIVATE);
String access_token = mPrefs.getString("access_token", null);
long expires = mPrefs.getLong("access_expires", 0);
if(access_token != null) {
facebook.setAccessToken(access_token);
}
if(expires != 0) {
facebook.setAccessExpires(expires);
}
if(!facebook.isSessionValid()) {
facebook.authorize(this, new String[] {"email", "user_birthday", "publish_actions"}, new DialogListener() {
@Override
public void onComplete(Bundle values) {}
@Override
public void onFacebookError(FacebookError error) {}
@Override
public void onError(DialogError e) {}
@Override
public void onCancel() {}
});
}
}
public void logoutFB(){
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
facebook.authorizeCallback(requestCode, resultCode, data);
try{
json = Util.parseJson(facebook.request("me"));
Log.e("FacebookConnect", "JSON " + json.toString());
}catch (JSONException e) {
Log.e("FacebookConnect", "JSONException " + e.toString());
}catch(FacebookError fbe){
Log.e("FacebookConnect", "FacebookError " + fbe.toString());
}catch (Exception e){
Log.e("FacebookConnect", "Exception " + e.toString());
}
Intent a = new Intent(FacebookConnectActivity.this, FacebookDataProcess.class);
a.putExtra(TAG_JSON, json.toString());
startActivity(a);
finish();
}
}
I think I've just got something that works:
in FacebookConnectActivity:
public static void logoutFB(){
if(facebook.isSessionValid()){
facebook.setAccessToken(null);
}
}
This method is called in a logoutbutton.onclick just like this:
FacebookConnectActivity.logoutFB();
Maybe it helps someone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.