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