Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 未为Android日历API配置访问权限_Java_Android_Calendar - Fatal编程技术网

Java 未为Android日历API配置访问权限

Java 未为Android日历API配置访问权限,java,android,calendar,Java,Android,Calendar,我正在尝试使用google日历api的java/android api访问它(我遵循了以下示例:) 我所做的是: private static final List<String> SCOPES = Arrays.asList(CalendarScopes.CALENDAR, CalendarScopes.CALENDAR_READONLY); private HttpTranspor

我正在尝试使用google日历api的java/android api访问它(我遵循了以下示例:)

我所做的是:

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();
}
我得到一个错误:

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

有人能帮我解决这个问题吗?谢谢

我发现了错误。我没有为API密钥使用完整的包名。在我确保API密钥中使用的包名等于它工作时在AndroidManifest.xml中定义的包名之后。

转到API控制台,并为其启用API访问project@njzk2我在那里有很多项目。我如何知道需要为哪个项目启用api?在您的教程中,您是否遵循了标记为“注册应用程序”的部分?是的,我这样做了。在projekt和api控制台上,日历api被激活。您是否使用引用的证书对应用程序进行签名?
{
  "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."
}