我在项目中使用了旧的 apprequests 对话框,如:
Bundle parameters = new Bundle();
parameters.putString("message","invite friends message...");
parameters.putString("data","invite friends data...");
parameters.putString("title","invite friends dialog title...");
if (facebook != null){
facebook.dialog(getActivity(), "apprequests", parameters,
new Facebook.DialogListener() {
@Override
public void onComplete(Bundle values) {
// todo:
}
});
}
我在facebook doc中找到了新的实现。 App Invites
appLinkUrl = "my app link...";
previewImageUrl = "my image url...";
if (AppInviteDialog.canShow()) {
AppInviteContent content = new AppInviteContent.Builder()
.setApplinkUrl(appLinkUrl)
.setPreviewImageUrl(previewImageUrl)
.build();
AppInviteDialog.show(activity, content);
}
这是邀请应用给朋友或任何其他方式的正确实现吗?如果是,那么我的消息和数据内容将放在哪里。
或者,如果我使用图形api请求,如:
String graphPath="/me/apprequests/";
GraphRequest request = GraphRequest.newGraphPathRequest(
accessToken, graphPath, graphCallback);
Bundle parameters = new Bundle();
parameters.putString("message","invite friends message...");
parameters.putString("data","invite friends data...");
parameters.putString("title","invite friends dialog title...");
request.setParameters(parameters);
request.executeAsync();
然后回复{"data":[]}
并且不显示任何对话框。什么是正确的实现?
答案 0 :(得分:3)
旧的应用请求已重命名为Game Requests,仅限游戏。
App Invites对话框最近刚刚推出,适用于所有移动应用(使用iOS或Android原生应用)。通过应用邀请对话框,您可以设置网址(已启用该应用程序链接),您还可以向邀请添加图片。但是,您无法预先填写消息,用户必须在其中输入。
答案 1 :(得分:2)
我得到了解决方案,在下面找到,这是facebook sdk4中应用请求对话框的新实现。
String appLinkUrl = "https://fb.me/...";
String previewImageUrl = ...;
final String TAG = "fbv4";
if (AccessToken.getCurrentAccessToken() == null) {
// start login...
} else {
FacebookSdk.sdkInitialize(activity.getApplicationContext());
CallbackManager callbackManager = CallbackManager.Factory.create();
FacebookCallback<AppInviteDialog.Result> facebookCallback= new FacebookCallback<AppInviteDialog.Result>() {
@Override
public void onSuccess(AppInviteDialog.Result result) {
Log.i(TAG, "MainACtivity, InviteCallback - SUCCESS!" + result.getData());
}
@Override
public void onCancel() {
Log.i(TAG, "MainACtivity, InviteCallback - CANCEL!");
}
@Override
public void onError(FacebookException e) {
Log.e(TAG, "MainACtivity, InviteCallback - ERROR! " + e.getMessage());
}
};
AppInviteDialog appInviteDialog = new AppInviteDialog(activity);
if (appInviteDialog.canShow()) {
AppInviteContent.Builder content = new AppInviteContent.Builder();
content.setApplinkUrl(appLinkUrl);
content.setPreviewImageUrl(previewImageUrl);
AppInviteContent appInviteContent = content.build();
appInviteDialog.registerCallback(callbackManager, facebookCallback);
appInviteDialog.show(activity, appInviteContent);
}
}
}