Gmail的OAuth的回调问题 - 我们无法验证与此应用程序相关联的名字,因为它运行在您的 [英] Gmail OAuth callback issue - We are unable to verify the name associated with this application because it runs on your
问题描述
我基本上使用的Gmail联系人API V3( HTTPS整合Gmail登录和联系人列表导入://developers.google.com/google-apps/contacts/v3/ )。对于调用API我得通过OAuth的认证用户。所有工作正常,但唯一的问题是,我得到的Web视图一个奇怪的消息,这将打开谷歌屏幕要求用户允许访问我的应用程序来访问他/她的联系方式。附件是问题的截图
我使用的code级低于
公共类GmailDialog扩展对话框{
私人ProgressDialog progressDialog1 = NULL;
ProgressDialog progressdialog;
公共静态OAuthConsumer消费;
公共静态OAuthProvider提供商;
字符串URL;
ContainerClass containerClass;
的WebView mWebView;
上下文CONTEXT1;公共GmailDialog(上下文的背景下,ProgressDialog progressDialog){
超级(上下文);
progressDialog1 = progressDialog;
CONTEXT1 =背景;
containerClass =新ContainerClass(CONTEXT1);
}@覆盖
保护无效的onCreate(捆绑savedInstanceState){
requestWindowFeature(Window.FEATURE_NO_TITLE);
StrictMode.ThreadPolicy政策=新StrictMode.ThreadPolicy.Builder()
.permitAll()建立()。
StrictMode.setThreadPolicy(政策);
super.onCreate(savedInstanceState);
的setContentView(R.layout.ln_dialog);
setWebView(progressDialog1);
}@燮pressLint(SetJavaScriptEnabled)
私人无效setWebView(最终ProgressDialog PD){
尝试{ 消费=新CommonsHttpOAuthConsumer(C.CONSUMER_KEY,
C.CONSUMER_SECRET);
供应商=新CommonsHttpOAuthProvider(C.REQUEST_URL +?范围=
+ URLEn coder.en code(C.SCOPE,C.ENCODING)
+与& xoauth_displayname =+ C.APP_NAME,C.ACCESS_URL,
C.AUTHORIZE_URL);
URL = provider.retrieveRequestToken(消费者,C.OAUTH_CALLBACK_URL);
}赶上(例外五){
e.printStackTrace();
} mWebView =(的WebView)findViewById(R.id.webkitWebView1);
如果(Build.VERSION.SDK_INT> = 11){
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE,NULL);
}
mWebView.getSettings()setJavaScriptEnabled(真)。
mWebView.loadUrl(URL);
mWebView.getSettings()。setRenderPriority(
WebSettings.RenderPriority.HIGH);
。mWebView.getSettings()setCacheMode(WebSettings.LOAD_NO_CACHE);
mWebView.setWebViewClient(新HelloWebViewClient(PD));
mWebView.setPictureListener(新PictureListener(){ @覆盖
公共无效onNewPicture(的WebView视图,画中画){
如果(progressdialog!=空|| progressdialog.isShowing()){
progressdialog.dismiss();
}
}
});}类HelloWebViewClient扩展WebViewClient { 公共HelloWebViewClient(ProgressDialog PD){
progressdialog = PD;
} @覆盖
公共无效onPageFinished(的WebView视图,字符串URL){
super.onPageFinished(查看,网址);
}
@覆盖
公共无效onPageStarted(的WebView视图,字符串URL,位图图标){
super.onPageStarted(查看,网址,图标);
如果(!progressdialog.isShowing()|| progressdialog == NULL){
如果(android.os.Build.VERSION.SDK_INT> = 11){
progressdialog =新ProgressDialog(CONTEXT1,
AlertDialog.THEME_HOLO_LIGHT);
}其他{
progressdialog =新ProgressDialog(CONTEXT1);
}
progressdialog.setMessage(正在加载...);
progressdialog.setIndeterminate(真);
progressdialog.setCancelable(假);
progressdialog.show();
}
} @覆盖
公共布尔shouldOverrideUrlLoading(的WebView视图,字符串URL){ 如果(url.contains(C.OAUTH_CALLBACK_URL)){
URI URI = Uri.parse(URL); 字符串验证= uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
尝试{
provider.retrieveAccessToken(消费者,验证);
}赶上(例外五){
e.printStackTrace();
}
共享preferences preFS = preferenceManager
.getDefaultShared preferences(CONTEXT1);
编辑编辑= prefs.edit();
edit.putString(OAuth.OAUTH_TOKEN,consumer.getToken());
的System.out.println(令牌+ consumer.getToken());
edit.putString(OAuth.OAUTH_TOKEN_SECRET,
consumer.getTokenSecret());
的System.out.println(TokenSecret:+ consumer.getTokenSecret());
edit.commit();
取消();
对于(OnVerifyListener D:听众){
d.onVerify(验证);
}
}否则如果(url.contains(https://abcd.com/)){
取消();
}其他{ view.loadUrl(URL);
} 返回true;
}}私人列表< OnVerifyListener>听众=新的ArrayList< OnVerifyListener>();
公共无效setVerifierListener(OnVerifyListener数据){
listeners.add(数据);
}
接口OnVerifyListener {
公共无效onVerify(字符串验证);
}
}
同意画面是正常的,这种类型的身份验证。
您可能需要重新配置一些在谷歌开发者控制台应用程序的设置,使你不黄看到消息。
I am integrating gmail login and contact list import basically using gmail contacts api v3 (https://developers.google.com/google-apps/contacts/v3/). For calling the API I have to get the user authenticated through OAuth. All works fine but the only issue is that I get a strange message in the web view which opens google screen to ask user to allow access to my app to access his/her contacts. Attached is the screenshot of the issue
The code class I'm using is below
public class GmailDialog extends Dialog {
private ProgressDialog progressDialog1 = null;
ProgressDialog progressdialog;
public static OAuthConsumer consumer;
public static OAuthProvider provider;
String url;
ContainerClass containerClass;
WebView mWebView;
Context context1;
public GmailDialog(Context context, ProgressDialog progressDialog) {
super(context);
progressDialog1 = progressDialog;
context1 = context;
containerClass = new ContainerClass(context1);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
super.onCreate(savedInstanceState);
setContentView(R.layout.ln_dialog);
setWebView(progressDialog1);
}
@SuppressLint("SetJavaScriptEnabled")
private void setWebView(final ProgressDialog pd) {
try {
consumer = new CommonsHttpOAuthConsumer(C.CONSUMER_KEY,
C.CONSUMER_SECRET);
provider = new CommonsHttpOAuthProvider(C.REQUEST_URL + "?scope="
+ URLEncoder.encode(C.SCOPE, C.ENCODING)
+ "&xoauth_displayname=" + C.APP_NAME, C.ACCESS_URL,
C.AUTHORIZE_URL);
url = provider.retrieveRequestToken(consumer, C.OAUTH_CALLBACK_URL);
} catch (Exception e) {
e.printStackTrace();
}
mWebView = (WebView) findViewById(R.id.webkitWebView1);
if (Build.VERSION.SDK_INT >= 11) {
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl(url);
mWebView.getSettings().setRenderPriority(
WebSettings.RenderPriority.HIGH);
mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
mWebView.setWebViewClient(new HelloWebViewClient(pd));
mWebView.setPictureListener(new PictureListener() {
@Override
public void onNewPicture(WebView view, Picture picture) {
if (progressdialog != null || progressdialog.isShowing()) {
progressdialog.dismiss();
}
}
});
}
class HelloWebViewClient extends WebViewClient {
public HelloWebViewClient(ProgressDialog pd) {
progressdialog = pd;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
}
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
super.onPageStarted(view, url, favicon);
if (!progressdialog.isShowing() || progressdialog == null) {
if (android.os.Build.VERSION.SDK_INT >= 11) {
progressdialog = new ProgressDialog(context1,
AlertDialog.THEME_HOLO_LIGHT);
} else {
progressdialog = new ProgressDialog(context1);
}
progressdialog.setMessage("Loading...");
progressdialog.setIndeterminate(true);
progressdialog.setCancelable(false);
progressdialog.show();
}
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains(C.OAUTH_CALLBACK_URL)) {
Uri uri = Uri.parse(url);
String verifier = uri.getQueryParameter(OAuth.OAUTH_VERIFIER);
try {
provider.retrieveAccessToken(consumer, verifier);
} catch (Exception e) {
e.printStackTrace();
}
SharedPreferences prefs = PreferenceManager
.getDefaultSharedPreferences(context1);
Editor edit = prefs.edit();
edit.putString(OAuth.OAUTH_TOKEN, consumer.getToken());
System.out.println("Token :" + consumer.getToken());
edit.putString(OAuth.OAUTH_TOKEN_SECRET,
consumer.getTokenSecret());
System.out.println("TokenSecret :" + consumer.getTokenSecret());
edit.commit();
cancel();
for (OnVerifyListener d : listeners) {
d.onVerify(verifier);
}
} else if (url.contains("https://abcd.com/")) {
cancel();
} else {
view.loadUrl(url);
}
return true;
}
}
private List<OnVerifyListener> listeners = new ArrayList<OnVerifyListener>();
public void setVerifierListener(OnVerifyListener data) {
listeners.add(data);
}
interface OnVerifyListener {
public void onVerify(String verifier);
}
}
The consent screen is normal for this type of authentication. You might need to re-configure some of the settings in the Google Developer Console for your application so that you don't see the message in yellow.
这篇关于Gmail的OAuth的回调问题 - 我们无法验证与此应用程序相关联的名字,因为它运行在您的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!