Kel*_*ton 4 post android facebook
我有个问题.我想使用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();
}
Run Code Online (Sandbox Code Playgroud)
我假设您在用户成功进行身份验证后正在执行该代码?
这段代码对我有用:
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();
}
Run Code Online (Sandbox Code Playgroud)
您可以在活动的onCreate()中调用onFacebookShare(),然后当用户按下任何内容以表明他/她想要在Facebook上分享时,请调用postToFBWall().当然,您必须添加处理以显示登录对话框.
归档时间: |
|
查看次数: |
12902 次 |
最近记录: |