谷歌端点 - 安卓GoogleAuthIOException井字 - 删除的ClientID [英] Google Endpoints - Android GoogleAuthIOException Tic Tac Toe - Removed clientIds

查看:297
本文介绍了谷歌端点 - 安卓GoogleAuthIOException井字 - 删除的ClientID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了谷歌端点井字例子 - 服务器code在Java中。

I downloaded the Google Endpoints Tic Tac Toe example - the server code in Java.

只是为了快速跑起来,我从API定义中删除了的ClientID,所以我可以很快看到它的工作在API浏览器:

Just to quickly run it up, I removed the clientIds from the API definition, so I could quickly see it working in the API Explorer:

@Api(name = "tictactoe", version = "v1")
public class ScoresV1
{
...

我可以使用API​​ Explorer中运行下面的方法就好了,与OAuth的开启与我的Gmail accoumnt验证。我可以看到用户对象设置到该帐户在调试器:

I could run the following method just fine using the API Explorer, with OAuth turned on and authenticating with my gmail accoumnt. I could see the "user" object set to that account in the debugger:

@ApiMethod(name = "scores.list")
@SuppressWarnings("unchecked")
public List<Score> list(@Nullable @Named("limit") String limit,
        @Nullable @Named("order") String order, User user)
        throws OAuthRequestException, IOException
{
    ...

然后我继续和生成的Andr​​oid客户端(用的ClientID仍然被删除)。我也下载了官方Android应用得到UI类和资源文件(账户选择器和游戏界面)。

I then went ahead and generated the Android client (with the clientIds still removed). I also downloaded the official Android app to get the UI classes and res files (account picker and the game interface).

而这正是我坚持。一个真正的Andr​​oid设备上运行时,下面的code在TictactoeActivity扔了GoogleAuthIOException:

And this is where I'm stuck. When running on a real Android device, the following code in TictactoeActivity threw a GoogleAuthIOException:

    @Override
    protected ScoreCollection doInBackground(Void... unused)
    {
        ScoreCollection scores = null;
        try
        {
            scores = service.scores().list().execute();
        }
        catch (IOException e)
        {
            e.printStackTrace();

下面是例外:

02-21 16:38:47.051: D/TicTacToe(6151): com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAuthIOException
02-21 16:38:47.051: D/TicTacToe(6151):  at com.google.api.client.googleapis.extensions.android.gms.auth.GoogleAccountCredential$RequestHandler.intercept(GoogleAccountCredential.java:286)
02-21 16:38:47.051: D/TicTacToe(6151):  at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:858)
...

挖了一点到源,我找到了根异常被抛出此code在GoogleAuthUtil.getToken(),这是有些无助:

Digging a bit more into the source, I found the root exception was thrown by this code in GoogleAuthUtil.getToken(), which is somewhat unhelpful:

com.google.android.gms.auth.GoogleAuthException: Unknown

现在,我有本地开发服务器上的断点ScoreV1.list(),与API浏览器进行测试时它被击中,但Android客户端失败,甚至没有击中服务器。现在,-a 0.0.0.0设置的本地开发服务器上接受传入的连接。我检查网址是否正确,以及,我可以运行在手机上的以下网址 Chrome浏览器(它给了我一个验证错误,因为没有用户设置,不过没关系):

Now, I have a breakpoint on the local dev server at ScoreV1.list(), which was hit when testing with the API Explorer, but the Android client failed without even hitting the server. Now, "-a 0.0.0.0" was set on the local dev server to accept incoming connections. I've checked the URL is correct as well, and I could run the following URL from the phone's Chrome browser (it gave me an Auth error since no user was set, but that's okay):

http://192.168.2.23:8888/_ah/api/tictactoe/v1/score?limit=1&order=1

所以我知道网络是否工作正常,手机能够获得它。我也验证了AndroidManifest.xml中具有下列权限设置:

So I know the network is working and the phone had access to it. I've also verified that AndroidManifest.xml has the following permissions set:

<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.USE_CREDENTIALS" />

这里的code表示TicTacToe.java我的网址和路径:

Here's the code showing my URL and path in TicTacToe.java:

    public static final String DEFAULT_ROOT_URL = "http://192.168.2.23:8888/_ah/api/";

/**
 * The default encoded service path of the service. This is determined when
 * the library is generated and normally should not be changed.
 * 
 * @since 1.7
 */
public static final String DEFAULT_SERVICE_PATH = "tictactoe/v1/";

/**
 * The default encoded base URL of the service. This is determined when the
 * library is generated and normally should not be changed.
 */
public static final String DEFAULT_BASE_URL = DEFAULT_ROOT_URL
        + DEFAULT_SERVICE_PATH;
...

现在,我百思不得其解,甚至如果我的DEFAULT_ROOT_URL更改为随机的,像5.5.5.5的东西,我得到完全相同的GoogleAuthIOException!我希望得到一个不同的异常时,主机不可达...

Now, the thing that really baffles me is even if I change the DEFAULT_ROOT_URL to something random, like 5.5.5.5, I get the exact same GoogleAuthIOException! I would expected to get a different exception when the host is unreachable...

另外,我试过部署服务器,以生产,并重新指向的URL [的myapp] .appspot.com地址 - 同样的结果。服务器日志从未注册过请求进入。

Also, I tried deploying the server to production, and repoint the URL to the [myapp].appspot.com address - same result. The server Log never registered a request coming in.

正因为如此,我现在真的卡住。请你帮助!万分感谢!

As it is, I'm now really stuck. Please do help! Thanks a million!!!

推荐答案

该错误是最有可能是由于授权Android应用程序和云端点API之间没有发生。

The error is most likely due to the authorization not happening between your Android application and the Cloud Endpoints API.

由于我没有完全进入您的实际端点的API注释和Android code,我建议你看一下以下几点紧密:

Since I do not have full access to your actual Endpoint API annotations and the Android code, I would suggest that you look at the following points closely:

  • 确保您已正确注明您的云API端点与的ClientID 观众。 Android的受众价值是相同的Web客户端编号的。

  • Ensure that you have annotated your Cloud Endpoints API correctly with the clientIds and audiences. The Android Audience value is the same as that of the Web Client Id.

请确保您已部署更新的API和再生的端点API源列入Android应用程序。

Make sure you have deployed the updated API and regenerated the Endpoints API sources for inclusion in your Android application.

最后,在你的机器人源$ C ​​$ C,你必须建立GoogleAccountCredential的一个实例,使用GoogleAccountCredential.usingAudience(...),然后使用此凭证对象,同时拨打电话到端点API 。对于如端点建设​​者需要一个HTTP传输,GSON厂和凭据。不要让最后一个参数(即凭证)为空。

Finally, in your Androids source code, you must build an instance of the GoogleAccountCredential, using the GoogleAccountCredential.usingAudience(...) and then use this credential object while making a call to the endpoint API. For e.g. the Endpoint builder takes a HTTP Transport, GSON Factory and the Credential. Do not leave the last parameter (i.e. Credential) as empty.

这篇关于谷歌端点 - 安卓GoogleAuthIOException井字 - 删除的ClientID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆