How to import a message with the Gmail API in Java - android

I've studied this page:
https://developers.google.com/gmail/api/v1/reference/users/messages/import
I have some messages I will be keeping track of in my Android program. I will be keeping a record of the messages I will be deleting and I would like to import those messages slated for deletion into a new folder (In Gmail API folders are called Labels).
I tried the test form:
POST https://www.googleapis.com/gmail/v1/users/omitted%40gmail.com/messages/import?deleted=false&internalDateSource=dateHeader&neverMarkSpam=true&processForCalendar=false&key={YOUR_API_KEY}
{
"payload": {
"body": {
"data": "hellio"
}
}
}
Response:
400 OK
- SHOW HEADERS -
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalidArgument",
"message": "'raw' RFC822 payload message string or uploading message via /upload/* URL required"
}
],
"code": 400,
"message": "'raw' RFC822 payload message string or uploading message via /upload/* URL required"
}
}
There is a problem sending the request but I am not sure at all what it means. What I need is some Java that sends a request that will import a message where I can specify the body, received date and subject line. Is it possible?
Thank you.
P.S. I just wanted to delete the attachments not the whole message but after reading the Gmail API documents it looks like this is not possible and is only possible through IMAP. The reason I am asking this question is so that I don't have to move my whole program to IMAP.

You are pretty close with your code. What you need to do is write a mail compliant with the RFC 2822 standard, and Base64-encode said mail and make it URL-safe (replace all + with - and all / with _) before inserting it.
You are better at Java than me, but if I would make a correct message in the browser's Developer Console, it could look something like this:
var encodedMail = btoa(
"Date: Thu, 1 Jan 1970 12:00:00 -0000\n" +
"From: emtholin#gmail.com\n" +
"To: emtholin#gmail.com\n" +
"Subject: Example Subject\n\n" +
"This is the body of the mail"
).replace(/\+/g, '-').replace(/\//g, '_');
Then I just insert this mail with the same request you issued:
POST https://www.googleapis.com/gmail/v1/users/me/messages?internalDateSource=dateHeader&key={YOUR_API_KEY}
{
"raw": "RGF0ZTogVGh1LCAxIEphbiAxOTcwIDEyOjAwOjAwIC0wMDAwCkZyb206IGVtdGhvbGluQGdtYWlsLmNvbQpUbzogZW10aG9saW5AZ21haWwuY29tClN1YmplY3Q6IEV4YW1wbGUgU3ViamVjdAoKVGhpcyBpcyB0aGUgYm9keSBvZiB0aGUgbWFpbA=="
}
As you can see, this worked great!

Related

How to handle dynamic error response in android using retrofit?

I am currently working on new android project with feathersjs back-end. Before error response normal format like,
{
"code": 123,
"message": "An error occurred!"
}
But now structure change dynamically according to the api request body. For Example I have three input field in my UI like Name, age, email after hitting api if wrong data error response will be like,
{
"code":123,
"error":{
"name":"Name is wrong",
"age":"Age is greater than 18 is mandatory",
"email:"Invalid email id"
}
}
So I need to link Error response to correct Edittext Field and set Error Message. How I link this ?. But Request Body field name and error response field name are same.
Request Body structure :
{
"data":{
"name":"xxx",
"age":"24",
"email:"xx#gmail.com"
}
}
Detail Explanation with Example Code will be more helpful.

Twilio SMS body doesn't concatenate URL parameters in Azure Logic App

I'm currently building a logic app in Azure to send text messages with Twilio. Everything is working smoothly except that I can't send complex URL in the body.
For exemple if I send this : https://example.com?id=26 I will recieve the the correct string, but the parameter is not concatenated correctly with the domain in the clickable link.
So when I click the link in the text message it only opens the https://example.com . The message I'm sending is built like this :
"Send_Text_Message_(SMS)": {
"inputs": {
"body": {
"body": "#{triggerBody()?['message']}#{triggerBody()?['url']}#{body('Insert_row')?['Id']}",
"from": "xxx-xxx-xxxx",
"to": "#triggerBody()?['phone']"
},
message: Hello please click this link
url :https://example.com?id=
id: 26
so the final body would be like : [message][url][id]
I've tried sending a simple string like https://example.com?id=8 to see if it was the "complex" body concatenation that was failing, but it's still not working.
Can anyone help :) ?
For anyone that would be stuck with this here's how I tricked android :
I added a / after the .com so now the url I'm sending is :
https://example.com/?id=36

How to get all the posts of a facebook page?

I want to get all the posts of a facebook page. I am following the link https://developers.facebook.com/docs/graph-api/reference/v2.8/post
For example URL : http://graph.facebook.com/v2.8/{page_id}/feed%20HTTP/1.1
I get the response as :
{"error":
{
"message": "Unknown path components: /feed HTTP/1.1",
"type": "OAuthException",
"code": 2500,
"fbtrace_id": "Em5dm7wPr9k"
}
}
I got the page_id from my facebook page.
Is my URL correct? Is this the correct way to get all the posts?
This is the correct way: https://developers.facebook.com/tools/explorer/?method=GET&path=bladauhu%2Ffeed&version=v2.8
You don´t need the Page ID, but you need to get rid of the " HTTP/1.1" in the API call. It´s just http://graph.facebook.com/v2.8/{page_id}/feed.

Keen IO Junks data with KeenIOClient for Android

Trying to use IO Keen for Android, i'm using Android Sample available here (https://github.com/keenlabs/KeenClient-Android-Sample) the data is being sent, but they are always duplicate and the second always contains junk.
The HashMap event is clean before adding in the queue.
Am I the only one?
Watch these :
{
"keen": {
"timestamp": "2015-01-22T18:08:49.863Z",
"created_at": "2015-01-22T18:09:07.589Z",
"id": "54c13cc3672e6c486c7a28bb"
},
"click-number": 0
}
{
"keen": {
"timestamp": "2015-01-22T18:09:07.590Z",
"created_at": "2015-01-22T18:09:07.590Z",
"id": "54c13cc3672e6c486c7a28bc"
},
"-537732783": 3
}
"-537732783": 3 What is that?
Logcat :
FINER: Sent request '{"android-sample-button-clicks":[{"click-number":0,"keen":{"timestamp":"2015-01-22T13:14:19.075-0500"}}]}' to URL 'https://api.keen.io [...]
FINER: Received response: '{"android-sample-button-clicks": [{"success": true}]}' (200)
FINER: Sent request '{"android-sample-button-clicks":[{"-1236199318":1}]}' to URL 'https://api.keen.io [...]
FINER: Received response: '{"android-sample-button-clicks": [{"success": true}]}' (200)
This was caused by a bug in the 2.1.0 release of the SDK. It has been fixed in the 2.1.1 release.
(In more detail: the bug was in the retry limiting logic that was added as part of 2.1. See this PR for the fix: https://github.com/keenlabs/KeenClient-Java/pull/37)
Sorry for the mistake!

Android push notification error in Corona

Even by using sample project provided in Corona SDk , I get a notification with error 400. I guess my json data is correct. Following is the code for Json message.
local jsonMessage =
[[
"registration_ids": ["]] .. tostring(googleRegistrationId) .. [["],
"data":
{
"alert": "Hello World!",
"sound": "default"
}
}
]]
This is the message on my device.
Based on the 400 error code, the problem must be your JSON :
400
Only applies for JSON requests. Indicates that the request could not
be parsed as JSON, or it contained invalid fields (for instance,
passing a string where a number was expected). The exact failure
reason is described in the response and the problem should be
addressed before the request can be retried.
With all the square brackets and html tag, it's really hard to understand from your question how your JSON actually looks like.
Anyway, here's how it should look like :
{
"registration_ids": ["some reg id"],
"data":
{
"alert": "Hello World!",
"sound": "default"
}
}
I solved this error by changing the format of my json and checking the format on this link http://jsonlint.com/# . This was a great help and also I replace alert icon by custom icon by using this:
http://developer.android.com/guide/practices/ui_guidelines/icon_design_status_bar.html

Categories

Resources