我已经编写了一个代码示例,用于在facebook上发送apprequest。
这是我的代码:
Facebook facebook = new Facebook(APP_ID);
Bundle params = new Bundle();
params.putString("title", "Goal Machine");//name
params.putString("message", sendInvite);//link
params.putString("to", Constant.facebookIdBuffer.toString());
params.putString("data", Constant.shortAppUrlForAndroid+"\n"+Constant.shortAppUrlForIphone);
facebook.dialog(_activity, "apprequests", params, new DialogListener() {//send
@Override
public void onComplete(Bundle values) {
Constant.facebookIdBuffer=null;
postToWall(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;
}
@Override
public void onCancel() {
Constant.showAlertDialog("Error", "Can't send ally request!", _activity.getParent(), false);
Constant.facebookIdBuffer=null;
}
});
但它不断显示错误对话框:
请告诉我出了什么问题..?
答案 0 :(得分:0)
使用以下代码完成任务: -
Bundle params = new Bundle();
params.putString("to", friendId);
params.putString("message", "I am using this app...this is an awesome app" + "\n You should try it.");
params.putString("frictionless", "1");
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();
final String requestId = values.getString("request");
if (requestId != null) {
Toast.makeText(context, "Request sent: " + requestIdd, Toast.LENGTH_SHORT).show();
}
} else {
Toast.makeText(context, "Request cancelled", Toast.LENGTH_SHORT).show();
}
}
}
}).build();
requestsDialog.show();