Dirk,
Please refer to the oauth documentation for understanding how to proceed.
Nico
Hi there,
I am trying to get the car2go "reqtoken" POST request up and running using Java 7 and the Apache HttpClient 4 libraries.
Unfortunately, the car2go system's response is always:
<HTTP/1.1 401 Unauthorized [Date: Sun, 28 Apr 2013 14:37:49 GMT, Server: IBM_HTTP_Server, WWW-Authenticate: OAuth realm="car2go_api", oauth_problem="signature_invalid", Vary: Accept-Encoding,User-Agent, Content-Length: 0, Keep-Alive: timeout=10, max=100, Connection: Keep-Alive, Content-Type: text/plain, Content-Language: en-US]
I added my Java code below, any hint to get it up and running is very welcome !
Thanks for your help!
Dirk
Stuttgart/Germany
---------
private void executeCar2Go() {
String requestUrl = "https://www.car2go.com/api/reqtoken";
HttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(requestUrl);
try {
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
nameValuePairs.add(new BasicNameValuePair("oauth_callback", "oob"));
nameValuePairs.add(new BasicNameValuePair("oauth_consumer_key", "<my consumer key>"));
nameValuePairs.add(new BasicNameValuePair("oauth_nonce", "6201190"));
nameValuePairs.add(new BasicNameValuePair("oauth_signature_method", "HMAC-SHA1"));
String ts = "" + (System.currentTimeMillis() / 1000);
nameValuePairs.add(new BasicNameValuePair("oauth_timestamp", ts));
nameValuePairs.add(new BasicNameValuePair("oauth_version", "1.0"));
nameValuePairs.add(new BasicNameValuePair("oauth_signature", "<my shared secret>")); // same as "my encoded signature" ??--
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(post);
System.out.println("response: " + response);
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = "";
while ((line = rd.readLine()) != null) {
System.out.println(line);
}
} catch (IOException e) {
e.printStackTrace();
}
}
You received this message because you are subscribed to the Google Groups "car2go OpenAPI" group.
To unsubscribe from this group and stop receiving emails from it, send an email to car2go-openap...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Thanks for a more detailled hint what my Java code does not do correctly!
Dirk Schesmer
Dirk,
You cannot get rid of te first login to the car2go site, because that is where the user must grant the permission. The verifier code does not have to be shown to and copied by the user, you can ask car2go (send them an e-mail) to redirect to a server page of your own where you can handle the transfer of the verifier yourself. You could temporarily store it next to the requesttoken for instance, and then have your application retrieve it and use it for the next step. You must store the access token and accesstokensecret safely in your application environment.
Good luck,
Nico