问题描述
我有一个问题。我想使用Facebook的API,使后到我的墙上,而无需调用一个对话框。基本上我有一个应用程序,我希望人们能够共享应用程序,所以我想有一个特定的消息发布。我不断收到法不执行的响应。继承人的code为后。
//我想这也是 - >>字符串路径=http://graph.facebook.com/me/feed;
字符串路径=https://api.facebook.com/method/stream.publish;
叠B =新包();
//而且我想这 - > b.putString(access_token,facebook.getAccessToken());
b.putString(消息,这只是一个测试...);
尝试 {
字符串RET = facebook.request(路径,B);
Toast.makeText(fmasterActivity.this,保留,Toast.LENGTH_LONG).show();
}赶上(MalformedURLException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}赶上(IOException异常E){
// TODO自动生成的catch块
e.printStackTrace();
}
我假设你正在做的code该位用户成功认证后?
的code此位为我工作:
私人facebook mFacebook;
私人AsyncFacebookRunner mAsyncRunner;
私人无效onFacebookShare(){
mFacebook =新的Facebook();
mAsyncRunner =新AsyncFacebookRunner(mFacebook);
SessionEvents.addAuthListener(新SampleAuthListener());
SessionEvents.addLogoutListener(新SampleLogoutListener());
}
私人无效postToFBWall(){
如果(mFacebook.isSessionValid()){
shareVideoOnFB();
} 其他 {
的ShowDialog(DIALOG_FBOOK_LOGIN);
}
}
公共无效shareVideoOnFB(){
捆绑PARAMS =新包();
params.putString(信息,此字符串显示为状态消息);
params.putString(链接,这是URL去);
params.putString(名,这将图片旁出现了);
params.putString(标题,这将出现在标题);
params.putString(说明,这将出现在标题下);
params.putString(图片,这是形象出现在后);
mAsyncRunner.request(ME /饲料,PARAMS,POST,新RequestListener(){
公共无效onMalformedURLException(MalformedURLException异常E){}
公共无效onIOException(IOException异常E){}
公共无效onFileNotFoundException(FileNotFoundException异常E){}
公共无效onFacebookError(FacebookError E){}
公共无效的onComplete(字符串响应){
logoutFacebook();
}
});
Toast.makeText(ShareActivity.this,张贴到墙上......,Toast.LENGTH_SHORT).show();
}
您可以致电onFacebookShare()在活动的onCreate(),然后当用户presses无论以表明他/她希望在Facebook上分享,请拨打postToFBWall()。当然,你必须处理到显示登录对话框中添加。
I have a problem. I want to use the facebook api and make a post to my wall without calling a dialog. Basically I have an app and I want people to be able to share the app, so I want to have a specific message to post. I keep getting a response of "Method not implemented". Heres the code for the post.
//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();
}
I am assuming that you are doing that bit of code after the user successfully authenticates?
This bit of code worked for me:
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();
}
You can call onFacebookShare() in your activity's onCreate(), and then when the user presses whatever to indicate that s/he wants to share on Facebook, call postToFBWall(). Of course you have to add in handling to show the login dialog.
这篇关于Android的Facebook的API后的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!