AndroidFacebook:在墙上张贴讯息

AndroidFacebook:在墙上张贴讯息,第1张

概述我想通过Android应用程序在自己的墙上发布一条消息.我有方法loginToFacebook()进行登录.在单击按钮时,如果用户已登录,我希望发布一条消息.我对FacebookAPI并不是很熟悉,因此我查看了Facebook开发人员文档和Internet上的其他站点来提出以下代码.但是,我的墙上没有任何消息.显然我

我想通过Android应用程序在自己的墙上发布一条消息.我有方法loginToFacebook()进行登录.在单击按钮时,如果用户已登录,我希望发布一条消息.我对Facebook API并不是很熟悉,因此我查看了Facebook开发人员文档和Internet上的其他站点来提出以下代码.但是,我的墙上没有任何消息.显然我错过了一些东西,但我不知道该怎么办,因为LogCat上没有错误.

public class ShareActivity extends Activity implements OnClickListener{    Facebook facebook = new Facebook("477110419013909");    AsyncFacebookRunner mAsyncRunner = new AsyncFacebookRunner(facebook);    String filename = "AndroIDSSO_data";    SharedPreferences mPrefs;  public voID onClick(VIEw arg0) {        loginToFacebook();        if (facebook.isSessionValID()) {            Bundle bundle = new Bundle();            bundle.putString("message","hey Facebook!");            try {                String strRet = facebook.request("/me/Feed",bundle,"POST");            } catch (fileNotFoundException e) {                // Todo auto-generated catch block                Log.e("Facebook", "Error: " + e.getMessage());            } catch (MalformedURLException e) {                // Todo auto-generated catch block                Log.e("Facebook", "Error: " + e.getMessage());            } catch (IOException e) {                // Todo auto-generated catch block                Log.e("Facebook", "Error: " + e.getMessage());            }}public voID loginToFacebook() {    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", "publish_stream" },                new DialogListener() {                    @OverrIDe                    public voID onCancel() {                        // Function to handle cancel event                    }                    @OverrIDe                    public voID onComplete(Bundle values) {                        // Function to handle complete event                        // Edit Preferences and update facebook acess_token                        SharedPreferences.Editor editor = mPrefs.edit();                        editor.putString("access_token",                                facebook.getAccesstoken());                        editor.putLong("access_expires",                                facebook.getAccessExpires());                        editor.commit();                    }                    @OverrIDe                    public voID one rror(DialogError error) {                        // Function to handle error                    }                    @OverrIDe                    public voID onFacebookError(FacebookError fberror) {                        // Function to handle Facebook errors                    }                });    }}}

我试着做

if (facebook.isSessionValID()) {            Bundle bundle = new Bundle();            bundle.putString("message","hey Facebook!");            facebook.dialog((Activity) this, "Feed", bundle,                    new DialogListener() {                        public voID onComplete(Bundle values) {                        }                        public voID onFacebookError(FacebookError error) {}                        public voID one rror(DialogError e) {}                        public voID onCancel() {}            }); }

也不起作用

解决方法:

我已经将此活动类用于发布图片:

public class poststatusFBActivity extends Activity { private static String[] PERMISSIONS =             new String[] {"photo_upload","publish_stream"};Bundle parems;//String status;private AsyncFacebookRunner mAsyncRunner;public final static String FB_APP_ID = "xxxxxxxx"; private Facebook fb;private Handler mHandler;//private ProgressDialog mProgressDialog;//private static String app_secret = "51a4b033e6cdbddf5761101d3eb09881";/** * @see androID.app.Activity#onCreate(Bundle) */@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    mHandler = new Handler();    Intent intent=getIntent();    parems=intent.getBundleExtra("params");    fb= new Facebook(poststatusFBActivity.FB_APP_ID);    SessionStore.restore(fb, this);    if (fb.isSessionValID())         post_status();    else        fb.authorize(this, PERMISSIONS,new AppLoginListener());}private class AppLoginListener implements DialogListener {    public AppLoginListener() {    }    public voID onCancel() {        Toast.makeText(getApplicationContext(), "Please accept to login", Toast.LENGTH_LONG).show();        finish();    }    public voID onComplete(Bundle values) {        /**         * We request the user's info so we can cache it locally and         * use it to render the new HTML snippets         * when the user updates her status or comments on a post.          */        mAsyncRunner=new AsyncFacebookRunner(fb);        post_status();    }    public voID one rror(DialogError e) {        Log.e("BTS", "dialog error: " , e);                   }    public voID onFacebookError(FacebookError e) {        Log.e("BTS ", "facebook error: " , e);        Toast.makeText(getApplicationContext(), "Facebook error", Toast.LENGTH_LONG).show();        finish();    }}protected voID onActivityResult(int requestCode, int resultCode,Intent data) {    //Facebook fb = Session.wakeupForAuthCallback();    fb.authorizeCallback(requestCode, resultCode, data);}public voID post_status() {    Log.e("BTS ____  ", " Post satus called ");    mAsyncRunner.request("me/photos", parems,"POST",new mRequestListener(),null);}public class mRequestListener implements RequestListener{    @OverrIDe    public voID onMalformedURLException(MalformedURLException e, Object state) {        Log.d("BTS", "******************* FACEBOOK::onMalformedURLException *******************");        e.printstacktrace();        finish();    }    @OverrIDe    public voID onIOException(IOException e, Object state) {        Log.d("BTS", "******************* FACEBOOK::onIOException *******************");        e.printstacktrace();        finish();    }    @OverrIDe    public voID onfileNotFoundException(fileNotFoundException e, Object state) {        Log.d("BTS", "******************* FACEBOOK::onfileNotFoundException *******************");        e.printstacktrace();        Toast.makeText(getApplicationContext(), "Image not found", Toast.LENGTH_LONG).show();        finish();    }    @OverrIDe    public voID onFacebookError(FacebookError e, Object state) {        Log.d("BTS", "******************* FACEBOOK::onFacebookError *******************");        e.printstacktrace();        Toast.makeText(getApplicationContext(), "Facebook error", Toast.LENGTH_LONG).show();        finish();    }    String msg="";    @OverrIDe    public voID onComplete(String response, Object state) {        Log.d("BTS", "******************* FACEBOOK::onComplete *******************");        // Todo auto-generated method stub        Log.d("Facebook-Example",                "News Feed: " + response.toString());        JsONObject Json;        /*JsONObject Json = Util.parseJson(response);            final String pictureURL = Json.getString("picture");            if (TextUtils.isEmpty(pictureURL)) {         * */        try {            Json = Util.parseJson(response);            Log.d("Facebook-Example",                    "News Feed: " + Json.toString(2));             final String post_ID = Json.getString("post_ID");             if (TextUtils.isEmpty(post_ID)) {                msg="Error in update status";             }else{                 msg="Status updated";             }             mHandler.post(new Runnable() {                    @OverrIDe                    public voID run() {                        Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG).show();                        //mProgressDialog.dismiss();                        finish();                    }             });        } catch (JsONException e) {            // Todo auto-generated catch block            e.printstacktrace();        } catch (FacebookError e) {            // Todo auto-generated catch block            e.printstacktrace();        }    }}

}

这是我从上一个活动传递的捆绑软件参数
byte [] data = null;
Bundle参数= new Bundle();
            params.putByteArray(“ photo”,data);
            params.putString(“ caption”,status);

您可以在Bundle中输入的其他值
params.putString(“ message”,“此字符串将显示为状态消息”);
        params.putString(“ link”,“这是要访问的URL”);
        params.putString(“ name”,“这将出现在图片旁边”);
        params.putString(“ caption”,“这将出现在标题下”);
        params.putString(“ description”,“这将显示在标题下”);
        params.putString(“ picture”,“这是要显示在帖子中的图像”);

总结

以上是内存溢出为你收集整理的Android / Facebook:在墙上张贴讯息全部内容,希望文章能够帮你解决Android / Facebook:在墙上张贴讯息所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1094772.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-28
下一篇 2022-05-28

发表评论

登录后才能评论

评论列表(0条)

保存