Android的Facebook发送消息 [英] Android facebook send a message
问题描述
我必须通过一个机器人app.I发送消息给Facebook好友做了所有的功能和尝试了code要发送消息给Facebook好友。但它显示一个错误对话框不可用于该设备。
I have to send a message to a facebook friend via an android app.I have done all functions and tried a code to send message to facebook friend.But it showing an error that the dialog is not available for this device.
下面是我的code发送消息给Facebook好友:
Here is my code to send a message to facebook friend:
Facebook facebook = new Facebook(APP_ID);
Bundle params = new Bundle();
params.putString("to", Constant.facebookIdBuffer.toString());
params.putString("name", "Goal Machine");//title
params.putString("link", Constant.shortAppUrlForAndroid+"\n"+Constant.shortAppUrlForIphone);//message
facebook.dialog(_activity, "send", params, new DialogListener() {//apprequests
@Override
public void onComplete(Bundle values) {
Constant.facebookIdBuffer=null;
//postToWall("@"+Constant.facebookIdBuffer.toString()+sendInvite);
}
@Override
public void onFacebookError(FacebookError error) {
Constant.showAlertDialog("Error", "Can't send ally request!", _activity.getParent(), false);
Constant.facebookIdBuffer=null;
}
@Override
public void onError(DialogError e) {
Constant.showAlertDialog("Error", "Can't send ally request!", _activity.getParent(), false);
Constant.facebookIdBuffer=null;
}
下面是屏幕短示值误差:
Here is the screen short showing error:
请给我建议的方式来发送带有链接的Facebook好友。
Please suggest me a way to send a message with links to facebook friend.
推荐答案
如果您要发送一些信息给朋友不是使用WebDialog。
下面是code,我使用并正常工作。
If you are trying to send some message to friends than use WebDialog. Below is code which i use and working fine.
private void sendRequestDialog(String msg, String json) {
Bundle params = new Bundle();
params.putString("message", msg);
params.putString("data", json);
WebDialog requestsDialog = (new WebDialog.RequestsDialogBuilder(
context, session, params)).setOnCompleteListener(
new OnCompleteListener() {
@Override
public void onComplete(Bundle values,
FacebookException error) {
if (error != null) {
if (error instanceof FacebookOperationCanceledException) {
Toast.makeText(context, "Request cancelled",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Network Error",
Toast.LENGTH_SHORT).show();
}
} else {
final String requestId = values
.getString("request");
if (requestId != null) {
Toast.makeText(context, "Request sent",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(context, "Request cancelled",
Toast.LENGTH_SHORT).show();
}
}
}
}).build();
requestsDialog.show();
}
这是它发送给朋友的消息的格式
And this is the format of a message which sends to friends
{
"id": "493703870648580",
"application": {
"name": "Send Requests How To",
"id": "403223126407920"
},
"to": {
"name": "Chris Abe Colm",
"id": "100003086810435"
},
"from": {
"name": "Christine Abernathy",
"id": "1424840234"
},
"data": "{\"badge_of_awesomeness\":\"1\",\"social_karma\":\"5\"}",
"message": "Learn how to make your Android apps social",
"created_time": "2012-10-07T17:29:57+0000"
}
这篇关于Android的Facebook发送消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!