gpt4 book ai didi

android facebook api 发布

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:01:05 26 4
gpt4 key购买 nike

我有一个问题。我想使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com