繁体   English   中英

使用谷歌API密钥的URL Shortener

[英]URL Shortener using google API key

我正在使用此代码来缩短我的长网址。 我做错了什么?

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."
}

看起来您已将应用程序打包在开发中(未签名)。 要在Android中使用此api,您必须在API控制台中注册您的Android应用程序将使用的密钥。

来自Google ::如果您的应用程序直接从Android访问API(而不是从Web服务器访问),那么要在控制台中注册数字签名的.apk文件的公共证书,您需要Android包名称和SHA-1指纹。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM