jjzjj

Android Google+ 登录不起作用 - statusCode=SIGN_IN_REQUIRED

coder 2023-12-27 原文

我正在尝试让用户使用 Google+ 登录。我在 Google 开发者控制台中创建了项目,获得了客户端 ID,并在 Android Studio 中安装了 Google Play 服务。 (我的运行设备是 Android 4.4.2) 当应用程序正在运行并且我按下登录按钮时,会出现一条 toast 消息: “内部错误”

Logcat 中的错误如下:

error ConnectionResult{statusCode=SIGN_IN_REQUIRED, resolution=PendingIntent{429ffe38: android.os.BinderProxy@429ffdd8}}

注意这个错误是在用户按下按钮之前出现的,其实我通过调试发现是出自这行代码:

Log.e(TAG, "error " + result.toString());

在方法中:

public void onConnectionFailed(ConnectionResult result) {
    if (!mGoogleIntentInProgress) {
        /* Store the ConnectionResult so that we can use it later when the user clicks on the Google+ login button */
        mGoogleConnectionResult = result;

        if (mGoogleLoginClicked) {
            /* The user has already clicked login so we attempt to resolve all errors until the user is signed in,
             * or they cancel. */
            resolveSignInError();
        } else {
            Log.e(TAG, "error " + result.toString());
        }
    }
}

这里是其他重要的方法:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    SignInButton googleLoginButton = (SignInButton) findViewById(R.id.login_with_google);
    googleLoginButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mGoogleLoginClicked = true;
            if (!mGoogleApiClient.isConnecting()) {
                if (mGoogleConnectionResult != null) {
                    resolveSignInError();
                } else if (mGoogleApiClient.isConnected()) {
                    getGoogleOAuthTokenAndLogin();
                } else {
                /* connect API now */
                    Log.d(TAG, "Trying to connect to Google API");
                    mGoogleApiClient.connect();
                }
            }
        }

    });

    /* Setup the Google API object to allow Google+ logins */
    mGoogleApiClient = new GoogleApiClient.Builder(this)
            .addConnectionCallbacks(this)
            .addOnConnectionFailedListener(this)
            .addApi(Plus.API)
            .addScope(Plus.SCOPE_PLUS_LOGIN)
            .build();
}

 private void resolveSignInError() {
    if (mGoogleConnectionResult.hasResolution()) {
        try {
            mGoogleIntentInProgress = true;
            mGoogleConnectionResult.startResolutionForResult(this, RC_GOOGLE_LOGIN);
        } catch (IntentSender.SendIntentException e) {
            // The intent was canceled before it was sent.  Return to the default
            // state and attempt to connect to get an updated ConnectionResult.
            mGoogleIntentInProgress = false;
            mGoogleApiClient.connect();
        }
    }
}

 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == RC_GOOGLE_LOGIN) {
        /* This was a request by the Google API */
        if (resultCode != RESULT_OK) {
            mGoogleLoginClicked = false;
        }
        mGoogleIntentInProgress = false;
        if (!mGoogleApiClient.isConnecting()) {
            mGoogleApiClient.connect();
        }
    }


}

这里是AndroidManifest.xml中的代码

<uses-permission android:name="android.permission.USE_CREDENTIALS" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.INTERNET" />

和元数据

   <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

希望您能帮帮我,非常感谢!

最佳答案

在我的项目中,Google+ 登录存在很多问题。例如,在创建 mGoogleApiClient 时,您应该

           mGoogleApiClient = new GoogleApiClient.Builder(this) 
                .addApi(Plus.API) 
                .addScope(Plus.SCOPE_PLUS_LOGIN) 
                .addScope(Plus.SCOPE_PLUS_PROFILE) 
                .addConnectionCallbacks(this) 
                .addOnConnectionFailedListener(this) 
                .build();

使用 SCOPE_PLUS_PROFILE - 用于访问用户的 Google+ 个人资料数据的 OAuth 2.0 范围。

您需要启用 Google+ API 并使用 SHA1 和您的程序包创建凭据。

OAuth 同意屏幕,其中包含您的电子邮件产品名称(必需)



更多,确保:

applicationId 标签
AndroidManifest.xml 中的包名
Google Developer Console 凭据中的包名称

都一样


更多,确保你有权限:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 

更多,在方法 @覆盖 protected void onActivityResult(int requestCode, int resultCode, Intent 数据 { ... ... }

不要需要调用super.onActivityResult(requestCode, resultCode, data);

还有更重要的事情:调试 keystore 发布 keystore

还有更多......

关于Android Google+ 登录不起作用 - statusCode=SIGN_IN_REQUIRED,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28882356/

有关Android Google+ 登录不起作用 - statusCode=SIGN_IN_REQUIRED的更多相关文章

  1. ruby-on-rails - rails : "missing partial" when calling 'render' in RSpec test - 2

    我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou

  2. ruby-on-rails - Rails 源代码 : initialize hash in a weird way? - 2

    在rails源中:https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb可以看到以下内容@load_hooks=Hash.new{|h,k|h[k]=[]}在IRB中,它只是初始化一个空哈希。和做有什么区别@load_hooks=Hash.new 最佳答案 查看rubydocumentationforHashnew→new_hashclicktotogglesourcenew(obj)→new_has

  3. ruby-on-rails - Rails 3 I18 : translation missing: da. datetime.distance_in_words.about_x_hours - 2

    我看到这个错误:translationmissing:da.datetime.distance_in_words.about_x_hours我的语言环境文件:http://pastie.org/2944890我的看法:我已将其添加到我的application.rb中:config.i18n.load_path+=Dir[Rails.root.join('my','locales','*.{rb,yml}').to_s]config.i18n.default_locale=:da如果我删除I18配置,帮助程序会处理英语。更新:我在config/enviorments/devolpment

  4. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  5. ruby-on-rails - 如果 Object::try 被发送到一个 nil 对象,为什么它会起作用? - 2

    如果您尝试在Ruby中的nil对象上调用方法,则会出现NoMethodError异常并显示消息:"undefinedmethod‘...’fornil:NilClass"然而,有一个tryRails中的方法,如果它被发送到一个nil对象,它只返回nil:require'rubygems'require'active_support/all'nil.try(:nonexisting_method)#noNoMethodErrorexceptionanymore那么try如何在内部工作以防止该异常? 最佳答案 像Ruby中的所有其他对象

  6. ruby-on-rails - 新 Rails 项目 : 'bundle install' can't install rails in gemfile - 2

    我已经像这样安装了一个新的Rails项目:$railsnewsite它执行并到达:bundleinstall但是当它似乎尝试安装依赖项时我得到了这个错误Gem::Ext::BuildError:ERROR:Failedtobuildgemnativeextension./System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/rubyextconf.rbcheckingforlibkern/OSAtomic.h...yescreatingMakefilemake"DESTDIR="cleanmake"DESTDIR="

  7. ruby - Sinatra set cache_control to static files in public folder编译错误 - 2

    我不知道为什么,但是当我设置这个设置时它无法编译设置:static_cache_control,[:public,:max_age=>300]这是我得到的syntaxerror,unexpectedtASSOC,expecting']'(SyntaxError)set:static_cache_control,[:public,:max_age=>300]^我只想将“过期”header设置为css、javaascript和图像文件。谢谢。 最佳答案 我猜您使用的是Ruby1.8.7。Sinatra文档中显示的语法似乎是在Ruby1.

  8. ruby - 使用 `+=` 和 `send` 方法 - 2

    如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:

  9. ruby - 如何计算 Liquid 中的变量 +1 - 2

    我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我

  10. ruby-on-rails - rails : check if the model was really saved in after_save - 2

    ActiveRecord用于在每次调用保存方法时调用after_save回调,即使模型没有更改并且没有生成插入/更新查询也是如此。这实际上是默认行为。在大多数情况下这没问题。但是一些after_save回调对模型是否实际保存的事情很敏感。有没有办法确定模型是否实际保存在after_save中?我正在运行以下测试代码:classStage 最佳答案 ActiveRecordusetocallafter_savecallbackeachtimesavemethodiscalledevenifthemodelwasnotchangedan

随机推荐