1
我正在使用此代碼來縮短我的長網址。我做錯了什麼?使用谷歌API密鑰的URL Shortener
Urlshortener.Builder builder = new Urlshortener.Builder (AndroidHttp.newCompatibleTransport(),
AndroidJsonFactory.getDefaultInstance(), null);
Urlshortener urlshortener = builder.build();
com.google.api.services.urlshortener.model.Url url = new com.google.api.services.urlshortener.model.Url();
url.setLongUrl(longUrl);
try {
Urlshortener.Url.Insert insert=urlshortener.url().insert(url);
insert.setKey(key);
url = insert.execute();
return url.getId();
} catch (IOException e) {
return null;
}
但它給了我例外。
com.google.api.client.googleapis.json.GoogleJsonResponseException: 403 Forbidden
{
"code": 403,
"errors": [
{
"domain": "usageLimits",
"message": "The Android package name and signing-certificate fingerprint, null and null, do not match the app restrictions configured on your API key. Please use the API Console to update your key restrictions.",
"reason": "ipRefererBlocked",
"extendedHelp": "https://console.developers.google.com/apis/credentials?project=796104768654"
}
],
"message": "The Android package name and signing-certificate fingerprint, null and null, do not match the app restrictions configured on your API key. Please use the API Console to update your key restrictions."
}
我添加了我的密鑰..並且還將包名和SHA-1指紋添加到了Google控制檯。仍然給我錯誤 – Sanket
但似乎根據他的錯誤,你還沒有簽署你的測試與apk。您是否出口簽署的包裹?或者運行調試 – tik27
是的。我簽署了apk。 – Sanket