Google 播放服务不可用。此应用程序将关闭

Google Play services is not available. This application will close

我是 android 开发的新手,我正在尝试 运行 来自 GitHub 的 Google Plus SDK sample android 示例项目使用 Android 工作室。我可以在 AVD kitkat/lollipop 设备中成功 运行 应用程序。但是在打开应用程序后,如果我 select "Request server with auth code?" 的复选框显示这个,

Error: the value of WEB_CLIENT_ID or SERVER_BASE_URL is not set correctly. This will cause error when requesting with server auth code.

截图 - 点击放大

我已经解决了这个错误,现在请看我的回答。但是我无法使用 google 加号按钮登录。

更新:

如果我尝试 运行在我的移动设备(物理设备)中使用相同的项目 运行通过 USB 连接的 Lollipop 5.0.1 会发生与上述相同的错误(与 AVD 相同)并且如果我单击 "Sign in" 按钮,它会显示选择一个帐户弹出窗口。如果我 select 我的电子邮件,然后按确定。我有另一条错误消息显示,

Google Play services is not available. This application will close.

但是我的 phone 上安装了所有播放服务应用程序,包括 Google+ 应用程序,其中 none 被禁用。我该如何解决这个错误,我是否遗漏了一些明显的东西?

问题一:错误:WEB_CLIENT_ID或SERVER_BASE_URL的值设置不正确

打开 MainActivity.java 并为您在 Google 开发人员控制台中创建的令牌交换服务器设置服务器基础 url 和 Web 应用程序令牌变量的客户端 ID,

// Client ID for a web server that will receive the auth code and exchange it for a
// refresh token if offline access is requested.
private static final String WEB_CLIENT_ID = "YOUR_CLIENT_ID";

// Base URL for your token exchange server, no trailing slash.
private static final String SERVER_BASE_URL = "http://yourtokenexchangeserver.com";

问题 2:Google 播放服务不可用。此应用程序将关闭。

您必须使用终端应用程序中的密钥工具创建签名证书指纹 (SHA1),然后尝试 运行 该应用程序。更多关于 this link.