本文介绍了Android Facebook Graph API 更新状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试通过 Android http 使用 Facebook 图 API 更新状态://developers.facebook.com/docs/reference/api/status/所以,我的问题是您是否可以给我一些示例代码来使用此 API 更新状态.
I've tried to update the status using the Facebook graph API with Android http://developers.facebook.com/docs/reference/api/status/So, my question is if you can give me some example code to update status using this API.
推荐答案
好的,这可能不是一个完美的代码,但它现在有效.您必须修改调用方式和时间以获得更好的用户体验:
Okay, This may not be a perfect code, but it works for now. You'll have to modify how and when it is called to get a better user Experience:
//Implementing SSO
facebook.authorize(this, new String[]{"publish_stream"}, new DialogListener(){
@Override
public void onComplete(Bundle values) {
updateStatus(values.getString(Facebook.TOKEN));
}
@Override
public void onFacebookError(FacebookError e) {
Log.d("FACEBOOK ERROR","FB ERROR. MSG: "+e.getMessage()+", CAUSE: "+e.getCause());
}
@Override
public void onError(DialogError e) {
Log.e("ERROR","AUTH ERROR. MSG: "+e.getMessage()+", CAUSE: "+e.getCause());
}
@Override
public void onCancel() {
Log.d("CANCELLED","AUTH CANCELLED");
}
});
这是更新的函数:
//updating Status
public void updateStatus(String accessToken){
try {
Bundle bundle = new Bundle();
bundle.putString("message", "test update");
bundle.putString(Facebook.TOKEN,accessToken);
String response = facebook.request("me/feed",bundle,"POST");
Log.d("UPDATE RESPONSE",""+response);
} catch (MalformedURLException e) {
Log.e("MALFORMED URL",""+e.getMessage());
} catch (IOException e) {
Log.e("IOEX",""+e.getMessage());
}
}
希望能帮到你.
这篇关于Android Facebook Graph API 更新状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!