Hallo,
ich versuche verzweifelt einen neuen Kalender mit Googles API einzutragen.
Hier ist mein Code:
Code
AccountManager accountmanager = AccountManager.get(Events.this.c);
String SCOPE = "https://www.googleapis.com/auth/calendar";
AccountManagerFuture<Bundle> authToken = accountmanager.getAuthToken(Events.this.account, "oauth2:" + SCOPE, null, Events.this.a,
null, null);
String accessToken = authToken.getResult().getString(AccountManager.KEY_AUTHTOKEN);
System.out.println("MYACCESSTOKEN: " + accessToken);
url = new URL("https://www.googleapis.com/calendar/v3/calendars?key=...");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(15000);
conn.setConnectTimeout(15000);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.addRequestProperty("client_id", "..." );
conn.addRequestProperty("Authorization", "OAuth " + accessToken);
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write("{\n" +
" resource\n" +
" {\n" +
" \"summary\": \"Test\"\n" +
" }\n" +
"}");
writer.flush();
writer.close();
os.close();
int responseCode=conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
String line;
BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line=br.readLine()) != null) {
response+=line;
}
}
else {
response="";
}
Alles anzeigen
Die Variable accessToken ist definitiv richtig.
Aber ich bekomme eine 400 HTTP Meldung als Antwort.
Was mache ich falsch?
(Den Key und das Oauth Passwort habe ich mit ... versehrt, ist aber definit richtig).