访问未配置为Android的Google日历API [英] Access Not Configured for Android Calendar API
问题描述
我想使用它的Java / Android的API来访问谷歌日历API(我跟着从例如:<一href=\"http://samples.google-api-java-client.google$c$c.com/hg/calendar-android-sample/instructions.html\" rel=\"nofollow\">http://samples.google-api-java-client.google$c$c.com/hg/calendar-android-sample/instructions.html).
I'm trying to access the google calendar api using its java/android API (I followed the example from: http://samples.google-api-java-client.googlecode.com/hg/calendar-android-sample/instructions.html).
我做的是以下内容:
private static final List<String> SCOPES = Arrays.asList(CalendarScopes.CALENDAR,
CalendarScopes.CALENDAR_READONLY);
private HttpTransport httpTransport = AndroidHttp.newCompatibleTransport();
private JsonFactory jsonFactory = GsonFactory.getDefaultInstance();
private GoogleAccountCredential credential;
@Override
protected void onCreate(Bundle savedInstanceState) {
credential = GoogleAccountCredential.usingOAuth2(this, SCOPES);
user = (User) getIntent().getExtras().getSerializable(User.KEY);
credential.setSelectedAccountName(user.getEmail());
// user.getEmail() is the value I previously retrieved from the selected
// android.accounts.Account.name
Calendar cal = new Calendar.Builder(httpTransport, jsonFactory, credential)
.setApplicationName("TestApp/1.0")
.build();
}
当我再打想这样做是为了获取calendarlist:
When I later call want to retrieve the calendarlist by doing this:
String pageToken = null;
do {
CalendarList calendarList = cal.calendarList()
.list()
.setPageToken(pageToken)
.execute();
calendars.addAll(calendarList.getItems());
pageToken = calendarList.getNextPageToken();
} while (pageToken != null);
我得到一个错误:
I get an error:
{
"code": 403,
"errors": [
{
"domain": "usageLimits",
"message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration.",
"reason": "accessNotConfigured",
"extendedHelp": "https://console.developers.google.com"
}
],
"message": "Access Not Configured. The API is not enabled for your project, or there is a per-IP or per-Referer restriction configured on your API key and the request does not match these restrictions. Please use the Google Developers Console to update your configuration."
}
谁能帮我解决这个问题?谢谢!
Can anyone help me to solve this problem? Thanks!
推荐答案
我发现了错误。我没有为API密钥使用完整的包名。之后,我确信,在API密钥用于包名是等于它的工作的AndroidManifest.xml中定义的包名。
I found the error. I didn't use the full package name for the API-Key. After I made sure that the package name used in the API-Key is equal to the package name defined in the AndroidManifest.xml it worked.
这篇关于访问未配置为Android的Google日历API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!