Hi out there,
In my opinion one of the most interesting things of the photon board in particular and IoT in general is the availability to connect cloud information with the electronic devices world. After some time doing similar things thought android apps and their IO interface, the IoT seems to be the natural way to do it. I’m newly with photon and my first days on it has been invested to get a clear image of their possibilities, and certainly I’m very exciting with this. Coming to the original question, I’m very interested on how to make a photon OAuth request to Google services API to update the status of an electronic design. From my understanding there is different strategies: One is use a HTTP client with POST data and other could be the WebHook. After some time reading and working on this, really I have not success with the HTTP client, probably due my lack of experience on this, and before of go ahead with WebHooks I’d like if somebody help me to take a decision on the better way to push on it.
The code for the HttpClient was as result to modify some examples on WebIDE but always get Error 404 as result.
The code for a simple request code to Google API was:
...
// Headers currently need to be set at init, useful for API keys etc.
http_header_t headers[] = {
//{ "Content-Type", "text/html" },
{ "content-type", "application/x-www-form-urlencoded" },
{ "cache-control", "no-cache"},
{ "Accept" , "*/*"},
{ "User-agent", "Particle HttpClient"},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
http_request_t request;
http_response_t response;
void setup() {
Serial.begin(9600);
}
void loop() {
if (nextTime > millis()) {
return;
}
Serial.println();
Serial.println("Application>\tStart of Loop.");
// Request path and body can be set at runtime or at setup.
request.hostname = "accounts.google.com";
//request.ip = remoteIP;
request.port = 80;
request.path = "/o/oauth2/device/code";
// The library also supports sending a body with your request:
request.body = "{\"client_id\":\"xxxxx\"}";
request.body = "{\"scope\":\"https://www.googleapis.com/auth/calendar\"}";
// Get request
http.post(request, response, headers);
Serial.print("Application>\tResponse status: ");
Serial.println(response.status);
Serial.print("Application>\tHTTP Response Body: ");
Serial.println(response.body);
nextTime = millis() + 10000;
}
the response is an 404 Error, instead the good one like the following:
{
"device_code": “xxxxxxxx",
"user_code": "EZDW-ERSW",
"verification_url": "https://www.google.com/device",
"expires_in": 1800,
"interval": 5
}
I was doing the request with Postman software like this:
but the response that I get from terminal is:
Application> Start of Loop.
Application> Response status: 404
Application> HTTP Response Body: <!DOCTYPE html><html lang=en><meta charset=utf-8><meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width"><title>Error 404 (Not Found)!!1</title><style>*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo
I’l appreciate any help on this.