谷歌翻译API错误(未配置)

时间:2014-07-22 02:12:11

标签: android api translate

我一遍又一遍地尝试让这件事情发挥作用,我似乎无法实现它。

我隐藏了apikey ......

我已在我的帐户中启用了Google翻译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 .... (我还去了窗口&gt;首选项&gt; android&gt; build&gt;并添加了调试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 ...我做错了,任何帮助都会有用

1 个答案:

答案 0 :(得分:1)

在项目的Google API控制台(https://console.developers.google.com/)中,转到API和Auth&gt;证书。在&#34;浏览器应用程序的密钥下,&#34;确保&#34;推荐人&#34;被设置为&#34;允许任何推荐者&#34;。

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

相关问题