1

我正在使用以下代码并尝试在 facebook 墙上发布消息以及图片 url。消息和图片 url 都是空的。任何人都可以找到并指导我正确的方向吗?

btnPostToWall.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            postToWall();
        }
    });


public void postToWall() {
    Bundle params = new Bundle();

    params.putString("message","test to post");

    params.putString("url", URLEncoder.encode("http://a.espncdn.com/photo/2010/0523/pg2_a_cricket_576.jpg"));

    try {
        String response = facebook.request("me/feed", params, "POST");
    } catch (FileNotFoundException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (MalformedURLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // post on user's wall.
    facebook.dialog(this, "feed", new DialogListener() {

        @Override
        public void onFacebookError(FacebookError e) {
        }

        @Override
        public void onError(DialogError e) {
        }

        @Override
        public void onComplete(Bundle values) {
        }

        @Override
        public void onCancel() {
        }
    });

}
4

1 回答 1

0

将此权限设置为公开

private String[] PERMISSIONS = new String[]

    { "publish_stream", "read_stream", "offline_access" };

如果是,这将检查会话是否存在,如果不存在,它将直接更新,然后询问用户是否允许在墙上更新。

按钮点击事件

    facebookConnector = new FacebookConnector(APP_ID, activity.getParent(), 
activity.getApplicationContext(),PERMISSIONS);
    if (facebookConnector.getFacebook().isSessionValid())
    {   
         postMessageInThread(position); // see method below 
    }
    else
    {
         SessionEvents.AuthListener listener = new SessionEvents.AuthListener()
    {

@Override
public void onAuthSucceed()
{
     postMessageInThread(position);
}

@Override
public void onAuthFail(String error)
{
}
};  

SessionEvents.addAuthListener(listener);
    facebookConnector.login();
}

这将更新您在墙上的数据

private void postMessageInThread(final int position)
    {
        Thread t = new Thread()
        {
            public void run()
            {
                try
                {
                    facebookConnector.postMessageOnWall(
                            "Your Text Data",
                            "Your Email URL","Description");
                    mFacebookHandler.post(mUpdateFacebookNotification);
                } catch (Exception ex)
                {
                    Log.e("", "Error sending msg", ex);
                }
            }
        };
        t.start();
    }

注意::这里的位置是我的列表记录,因此请根据该记录管理您的数据。

于 2013-01-31T10:41:26.110 回答