【问题标题】:Google Translate API Error (Unconfigured)Google 翻译 API 错误(未配置)
【发布时间】:2014-07-22 10:24:10
【问题描述】:

我一遍又一遍地尝试让这件事发挥作用,但我似乎无法做到。

我隐藏了 apikey...

我已在我的帐户中启用了 Google Translate API,并发表了这篇文章:

public class handleStuff extends AsyncTask<String, Integer, String>
        {
            @Override
            protected String doInBackground(String... arg0) {
                translateTest();
                return null;
            }
        }

    private static byte[] buff = new byte[1024];
    void translateTest()
    {
        String apiKey = "HIDDEN...";
        String url = "https://www.googleapis.com/language/translate/v2?key="+apiKey+"&source=en&target=de&q=Hello%20world";
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(url);

        try {
            //et.append("Try \n");
            HttpResponse response = client.execute(request);
            //et.append("Pass");
            StatusLine status = response.getStatusLine();
            //et.append(response.toString());
            if(status.getStatusCode() != 200) {
                //et.append("Error !200\n");    
            }
            HttpEntity entity = response.getEntity();
            InputStream is = entity.getContent();
            ByteArrayOutputStream content = new ByteArrayOutputStream();

            int readCount = 0;
            while( (readCount = is.read(buff)) != -1 )
            {
                content.write(buff, 0, readCount);
            }
            String retVal = new String(content.toByteArray());
            Log.d("Output", retVal);
            otp = retVal;
            //et.append("Translate" + retVal);

        } catch (Exception e)
        {
            //et.append("Exception:\n" + e.getMessage() + "\n");
            Log.d("Output", "Err:" + e.getMessage());
            e.printStackTrace();
            //throw new ApiException("Server Connect Problem" + e.getMessage(), e);
        }

    }

我已经为 android 添加了公共 API 访问权限并输入了我的 SHA1;com.... (我也去了 window>preferences>android>build> 并添加了调试 SHA1)... 但是,当我运行它时,我得到以下响应:

07-21 22:07:07.264: D/Output(18472): {
07-21 22:07:07.264: D/Output(18472):  "error": {
07-21 22:07:07.264: D/Output(18472):   "errors": [
07-21 22:07:07.264: D/Output(18472):    {
07-21 22:07:07.264: D/Output(18472):     "domain": "usageLimits",
07-21 22:07:07.264: D/Output(18472):     "reason": "accessNotConfigured",
07-21 22:07:07.264: D/Output(18472):     "message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
07-21 22:07:07.264: D/Output(18472):    }
07-21 22:07:07.264: D/Output(18472):   ],
07-21 22:07:07.264: D/Output(18472):   "code": 403,
07-21 22:07:07.264: D/Output(18472):   "message": "Access Not Configured. Please use Google Developers Console to activate the API for your project."
07-21 22:07:07.264: D/Output(18472):  }
07-21 22:07:07.264: D/Output(18472): }

我知道我拥有正确的 API 密钥,因为它知道我的应用程序不被允许。所以它一定是 SHA1 的问题;com ......我做错了,任何帮助都会很有用

【问题讨论】:

    标签: android api translate


    【解决方案1】:

    在您的项目的 Google API 控制台 (https://console.developers.google.com/) 中,转到 APIs and Auth > Credentials。在“浏览器应用程序的密钥”下,确保将“Referrers”设置为“允许的任何引荐来源网址”。

    如果不是,请单击编辑允许的推荐人并清除所有条目。

    【讨论】:

    • 这是 Android 应用的密钥
    • 然而,我现在意识到我正在使用一个 Http 请求......所以谷歌将它作为一个浏览器来处理。谢谢,如何将其作为 android 应用程序接口?
    • 看看this
    • 仅将其作为网络浏览器连接有什么缺点吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 2016-08-22
    • 2014-01-27
    • 2014-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多