我必须通过Android应用程序向facebook朋友发送消息。我已经完成了所有功能,并尝试使用代码向Facebook朋友发送消息。但是它显示错误,该对话框不可用于此设备
以下是我向Facebook好友发送消息的代码:
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;
}
这是屏幕短显示错误:
请建议我发送一条带有Facebook好友链接的消息。
答案 0 :(得分:0)
Send dialog
,因此您有3个选项:
答案 1 :(得分:0)
如果您尝试向朋友发送一些消息而不是使用WebDialog。 下面是我使用和工作正常的代码。
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();
}
这是发送给朋友的消息格式
{
"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"
}
答案 2 :(得分:0)
您可以使用最新Facebook Android sdk中的MessengerUtils发送带附件的邮件。
您可以使用以下mime类型发送附件:
发送图片的示例代码如下所示
String mimeType = "image/jpeg";
// contentUri points to the content being shared to Messenger
ShareToMessengerParams shareToMessengerParams =
ShareToMessengerParams.newBuilder(contentUri, mimeType)
.build();
// Sharing from an Activity
MessengerUtils.shareToMessenger(
this,
REQUEST_CODE_SHARE_TO_MESSENGER,
shareToMessengerParams);