Android的Facebook的图形API更新状态 [英] Android Facebook Graph API to update status

查看:104
本文介绍了Android的Facebook的图形API更新状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用更新与Android HTTP Facebook的图形API的状态: //developers.facebook.com/docs/reference/api/status/ 所以,我的问题是,如果你能给我一些例子code。使用此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.

推荐答案

好吧,这可能不是一个完美的code,但它现在。你将不得不修改如何以及何时它被调用,以获得更好的用户体验:

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());
    }
}

我希望它能帮助。

I hope it helps.

这篇关于Android的Facebook的图形API更新状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆