0
我一直試圖得到這個東西的工作,我似乎無法做到這一點。谷歌翻譯API錯誤(未配置)
我已經隱藏apikey ...
我已經啓用谷歌翻譯API在我的帳戶,且已經發了這個帖子像這樣:針對Android
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);
}
}
我加入了公共API訪問和輸入我的SHA1; COM .... (我也去窗口>首選項>安卓>建立>,並添加了調試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 ...我做錯了,任何幫助都會有用
那是哪裏? – Jister13
這是Android應用程序的關鍵 – Jister13
但是,現在我意識到我正在使用Http請求...所以Google將它作爲瀏覽器處理。謝謝,如何將這個接口作爲一個Android應用程序? – Jister13