[英]Error when trying to show Facebook Android SDK Add Friend Dialog
I'm trying to show a add friend dialog via the fb sdk. 我正在尝试通过fb sdk显示添加朋友对话框。
Bundle parameters = new Bundle();
parameters.putString("id", i.getUid());
FacebookSession.getSession().dialog(getSherlockActivity(), "friends", parameters,
new Facebook.DialogListener()
{
public void onFacebookError( FacebookError e ) { }
public void onError(DialogError e) { }
public void onCancel() { }
@Override
public void onComplete(Bundle values) {
// TODO Auto-generated method stub
}
} );
There is a loading screen and a dialog frame appears, but the content is just: 有一个加载屏幕,并显示一个对话框,但内容仅是:
The redirect_uri URL protocol must be HTTP or HTTPS
redirect_uri URL协议必须为HTTP或HTTPS
Usually a redirect_uri has not to be specified when creating a facebook dialog. 通常,在创建Facebook对话框时不必指定redirect_uri。 Even when I try to specify one manually, for example with:
即使我尝试手动指定一个,例如:
parameters.putString("redirect_uri", "http://www.facebook.com");
it returns the same error. 它返回相同的错误。
Anyone any ideas? 有任何想法吗?
Facebook supports only feed, Oauth and Apprequest actions in a "dialog" request. Facebook在“对话”请求中仅支持feed,Oauth和Apprequest操作。 For these requests even if the redirect_uri is specified as "fbconnect://success", it will not give the error "redirect_uri URL protocol should be http or https".
对于这些请求,即使将redirect_uri指定为“ fbconnect:// success”,也不会给出错误“ redirect_uri URL协议应为http或https”。 Unfortunately when we issue a friend dialog facebook is excepting the redirect_uri to be http/https and also redirect_uri should have the domain name defined in the "SITE URL" parameter in APP settings.
不幸的是,当我们发布一个朋友对话框时,facebook除了将redirect_uri设置为http / https之外,而且redirect_uri也应具有APP设置中“ SITE URL”参数中定义的域名。
Anyways, we fixed this issue by overriding the redirect_uri in facebook SDK. 无论如何,我们通过覆盖facebook SDK中的redirect_uri解决了此问题。 In facebook.java we made the following changes to the dialog method:
在facebook.java中,我们对对话框方法进行了以下更改:
public void dialog(Context context, String action, Bundle parameters,
final DialogListener listener) {
String endpoint = DIALOG_BASE_URL + action;
parameters.putString("display", "touch");
Start code change--->> Here you are overriding the redirect_uri with your SITE URL if the action is friends 更改起始代码--- >>如果操作是朋友,则在这里使用您的SITE URL覆盖redirect_uri
if(action.contentEquals("friends"))
{
parameters.putString("redirect_uri", "http://www.yourdomain.com");
}
else
{
parameters.putString("redirect_uri", REDIRECT_URI);
}
End code change 结束码变更
if (action.equals(LOGIN)) {
parameters.putString("type", "user_agent");
parameters.putString("client_id", mAppId);
} else {
parameters.putString("app_id", mAppId);
}
if (isSessionValid()) {
Start code change--->> We don't need access_token during a friend dialog 更改开始代码--- >>在好友对话框中,我们不需要access_token
if(!action.contentEquals("friends"))
parameters.putString(TOKEN, getAccessToken());
End code change 结束码变更
}
String url = endpoint + "?" + Util.encodeUrl(parameters);
if (context.checkCallingOrSelfPermission(Manifest.permission.INTERNET)
!= PackageManager.PERMISSION_GRANTED) {
Util.showAlert(context, "Error",
"Application requires permission to access the Internet");
} else {
new FbDialog(context, url, listener).show();
}
} Another tricky part is in FbDialog.java there is a Webview client that process the return code from facebook you have to make the following change to FbDialog.java: }另一个棘手的部分是FbDialog.java中有一个Webview客户端,它处理来自facebook的返回码,您必须对FbDialog.java进行以下更改:
private class FbWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Util.logd("Facebook-WebView", "Redirect URL: " + url);
if (url.startsWith(Facebook.REDIRECT_URI)) {
Bundle values = Util.parseUrl(url);
String error = values.getString("error");
if (error == null) {
error = values.getString("error_type");
Util.logd("Facebook-WebViewError", "error type: " + error);
}
else
Util.logd("Facebook-WebViewError", "error: " + error);
if (error == null) {
mListener.onComplete(values);
} else if (error.equals("access_denied") ||
error.equals("OAuthAccessDeniedException")) {
mListener.onCancel();
} else {
mListener.onFacebookError(new FacebookError(error));
}
FbDialog.this.dismiss();
return true;
} else if (url.startsWith(Facebook.CANCEL_URI)) {
mListener.onCancel();
FbDialog.this.dismiss();
return true;
} else if (url.contains(DISPLAY_STRING)) {
return false;
}
Start code change--->> During a friends dialog, redirect_uri is your SITE URL, so check for that in the url variable and process success and failure accordingly 更改起始代码--- >>在好友对话框中,redirect_uri是您的SITE URL,因此请检查url变量中的内容并相应地处理成功和失败
else if (url.startsWith("http://www.yourdomain.com")) {
Bundle values = Util.parseUrl(url);
String error = values.getString("error");
if (error == null) {
error = values.getString("error_type");
Util.logd("Facebook-WebViewError", "error type: " + error);
}
else
Util.logd("Facebook-WebViewError", "error: " + error);
if (error == null) {
mListener.onComplete(values);
} else if (error.equals("access_denied") ||
error.equals("OAuthAccessDeniedException")) {
mListener.onCancel();
} else {
mListener.onFacebookError(new FacebookError(error));
}
FbDialog.this.dismiss();
return true;
}
// launch non-dialog URLs in a full browser
// getContext().startActivity(
// new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
End code change 结束码变更
return false;
}
I filed a bug report at developers.facebook.com and got the following answer: 我在developers.facebook.com上提交了错误报告,并得到以下答案:
Our SDKs do not support adding friends.
我们的SDK不支持添加朋友。 Refer here >(https://developers.facebook.com/docs/reference/androidsdk/) for our documentation on what is >supported.
请参阅此处>(https://developers.facebook.com/docs/reference/androidsdk/)了解我们支持的文档。
If you still run across problems, feel free to post at our community website >(http://facebook.stackoverflow.com/) and tag with "android".
如果您仍然遇到问题,请随时在我们的社区网站>(http://facebook.stackoverflow.com/)上发布并标记为“ android”。
Thanks, Jesse
谢谢,杰西
which I don't understand because there is a dialog for adding friends and now it's not supported 我不明白,因为有一个添加朋友的对话框,现在不支持
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.