android facebook api 发布

标签 android facebook post

我有一个问题。我想使用 facebook api 并在不调用对话框的情况下在我的墙上发帖。基本上我有一个应用程序,我希望人们能够共享该应用程序,所以我想发布一条特定的消息。我不断收到“方法未实现”的回复。这是帖子的代码。

//I tried this also ->>String path = "http://graph.facebook.com/me/feed";
String path = "https://api.facebook.com/method/stream.publish";
Bundle b = new Bundle();
//And i tried this -> b.putString("access_token",facebook.getAccessToken());
b.putString("message", "this is just a test...");
try {
    String ret = facebook.request(path, b);
    Toast.makeText(fmasterActivity.this, ret, Toast.LENGTH_LONG).show();
    } catch (MalformedURLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

最佳答案

我假设您在用户成功通过身份验证后执行那段代码?

这段代码对我有用:

private Facebook mFacebook;
private AsyncFacebookRunner mAsyncRunner;

private void onFacebookShare() {
    mFacebook = new Facebook();
    mAsyncRunner = new AsyncFacebookRunner(mFacebook);

    SessionEvents.addAuthListener(new SampleAuthListener());
    SessionEvents.addLogoutListener(new SampleLogoutListener());
}

private void postToFBWall() {
    if(mFacebook.isSessionValid()){
        shareVideoOnFB();
    } else {
        showDialog(DIALOG_FBOOK_LOGIN);
    }
}

public void shareVideoOnFB(){
    Bundle params = new Bundle();
    params.putString("message", "This string will appear as the status message");
    params.putString("link", "This is the URL to go to");
    params.putString("name", "This will appear beside the picture");
    params.putString("caption", "This will appear under the title");
    params.putString("description", "This will appear under the caption");
    params.putString("picture", "This is the image to appear in the post");

    mAsyncRunner.request("me/feed", params, "POST", new RequestListener() {
        public void onMalformedURLException(MalformedURLException e) {}
        public void onIOException(IOException e) {}
        public void onFileNotFoundException(FileNotFoundException e) {}
        public void onFacebookError(FacebookError e) {}
        public void onComplete(String response) {
            logoutFacebook();
        }
    }); 

    Toast.makeText(ShareActivity.this, "Posting to your Wall...", Toast.LENGTH_SHORT).show();       
}

您可以在 Activity 的 onCreate() 中调用 onFacebookShare(),然后当用户按任何指示他/她想要在 Facebook 上分享时,调用 postToFBWall()。当然,您必须添加处理以显示登录对话框。

关于android facebook api 发布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4093618/

相关文章:

java - 如何通过检查数组值将数组拆分为不同数组或具有不同键的同一数组

java - Android:提高音乐播放器应用的效率

java - 几次调用后,facebook android SDK java.io.EOFException

iOS 应用程序和发布到 FaceBook

PHP 动态数据库插入

android - 当通过音频采样的数据数量超过 AudioRecord 构造函数中设置的 "bufferSizeInBytes"时会发生什么?

android - openCV android检测形状和颜色(HSV)

ruby-on-rails - 需要 Twitter 和 Facebook Gems 的推荐

android - Android 上对 REST API 的 POST 请求未获取参数

swift - 图像未通过 POST 完整传输到服务器