All,
I am planning to connect to GMAIL REST API from my mobile app that i am developing using Swift. so within the app, i would want to get inbox and sent items from an user and send it for further analysis. But when i explored the options to connect to GMail Rest API, i see only below options available. Java | PHP | .Net | Python
So wondering if there is any way we can still directly connect to GMail Rest API?
If it is a REST API, you just need to make HTTP requests to it to get data back. https://developers.google.com/gmail/api/v1/reference/ is a list of the URIs that you need to target with your HTTP requests. For example, a GET request to such an endpoint in Swift would look like:
let url = NSURL(string: " https://www.googleapis.com/gmail/v1/users/{userId}/drafts")
let task = NSURLSession.sharedSession().dataTaskWithURL(url!){
(data, response, error) in
println(NSString(data: data, encoding: NSUTF8StringEncoding))
}
task.resume()
would get all the drafts in a user's inbox. This would be in the data variable, which you would parse in the completion block of the dataTaskWithURL method. You would of course need to replace {userId} with a valid userId. REST is just a standard of using HTTP methods (GET PUT POST DELETE) to operate on resources. I would recommend reading up on REST and HTTP methods in Swift. As for the thing about it being for Java | PHP | Python | .NET, that probably just means they wrapped their REST API for those languages to make using it easier. You can still use it from any language that supports HTTP requests.
The example I provided was just for a GET request. Other types of requests will be structured differently, as you will need to provide a body with parameters. You may also need to provide a header with content-type, but someone with more experience with the gmail API might be able to tell you that.