Using SwiftyJSON with Gmail API - swift2

I am trying to make a simple email app to learn how to work with REST API's like the Gmail API and Im using SwiftyJSON to work with the responses I get from my requests.
I'm trying to get who the sender of an email. Im using the following requests to get the message object back. https://developers.google.com/gmail/api/v1/reference/users/messages/get
From the JSON Data I need to go to the following path (payload>headers>from) to get who sent the message now I have tried all the ways that are specified on the github page.
//Getting a string using a path to the element
let path = [1,"list",2,"name"]
let name = json[path].string
//Just the same
let name = json[1]["list"][2]["name"].string
//Alternatively
let name = json[1,"list",2,"name"].string
All of these ways return null.
Now when i do the following i get the payload object of the message object in return
let from = json["payload"]
What am I doing wrong here?

Related

Calling Graph Api from Web Api doesn't return all user data

In my ASP.NET Core Web Api, I'm trying to call Graph API to retrieve the data of other users in the organization. I'm using the On Behalf Of flow. The bootstrap token is passed in from SPA client code.
In the Startup code, I have:
builder.Services
.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddMicrosoftIdentityWebApi(builder.Configuration)
.EnableTokenAcquisitionToCallDownstreamApi()
.AddMicrosoftGraph("https://graph.microsoft.com/beta", "user.read user.readbasic.all profile")
.AddInMemoryTokenCaches();
In the Controller's Action, I have:
_graphServiceClient.Users.Request()
.Filter($"mail eq 'someuser#myorg.com'")
.Select((user) => new {
DisplayName = user.DisplayName,
City = user.City,
Country = user.Country,
BusinessPhones = user.BusinessPhones
})
.Request()
.GetAsync();
However, at runtime, I only get the DisplayName value. I don't get the values of City, Country or BusinessPhones. They are al null.
When I tried the same query in Graph Explorer, I saw the values for all of them.
What am I missing?
First, your code snippet has an error that you wrote 2 .Request(), you should remove one.
Whatever flow you used are all generating an access token so that you can access the api, therefore when you got correct data from the api, that means you have a right setting in using the flow, so I think if there's any issue, it should locate at the part of calling api. Then I did some test in my side.
Could you pls check if you call the api directly, you can get the value of City, Country and BUsinessPhones these 3 properties? Per my test, when I call the api, I can get response like screenshot below and by default it's null
https://graph.microsoft.com/beta/users?$filter=mail eq
'tinywang#xxx.onmicrosoft.com'&$select=mail,city,country,DisplayName,BusinessPhones,userType,usageLocation
And when I followed this tutorial to call the api via sdk, I got the same result:
My idea is checking the response of calling the api first and if we can't find the issue, then could you pls provide the tutorial you followed to help reproduce the issue.

Zoho Deluge - Read/Get ticket attachment content

I am currently trying to run a custom function in Zoho Desk that is triggered on ticket creation, targeting tickets created by our support#zoho... email address, that converts incoming emails into tickets.
More specifically, when an email contains a JSON attachment, I would like the custom function to be able to read the attachment and pull the JSON data from the attachment.
Is this possible? Has anyone had any success?
Below is the code I have, thought I was on the right track but run into the error below
//TicketID is set as an Argument for the custom function
ORGID = "********";
getthread = zoho.desk.getRelatedRecords(ORGID,"threads","tickets",TicketID);
threadid = getthread.getJSON("data").getJSON("id");
getthreadcontent = zoho.desk.getRelatedRecordById(ORGID,"threads",threadid,"tickets",TicketID);//.getJSON("content");
info getthreadcontent.getJSON("attachments").getJSON("name"); //Prints the Attachment Name (Works)
info getthreadcontent;//.getJSON("attachments").getJSON("href");//Prints the Attachment URL (Works)
response = invokeUrl
[
url: getthreadcontent.getJSON("attachments").getJSON("href")
type: GET
];
The above code returns this error:
{"errorCode":"UNAUTHORIZED","message":"You are not authenticated to perform this operation."}
Any help or pointers would be greatly appreciated :)
It looks like you might need to add your Zoho Auth Token to the URL, first, and then make the invoke_url() call.

REST service returning wrong content-type if file created has its header set to some value in iOS objective C

In iOS I am using AFNetworking for calling the web-services. Here I am getting the error: "unacceptable content type: application/excel". After a lot of struggle I came to know that it is the server team problem. I have a question regarding this:
Before returning the response of service call to the app, notification is being sent and at the same time the notification information(text, time, etc) is logged in notification.xls file on the server where the header is set for the file like below,
function calledWhenServiceCalled(){
someJsonArray; //generate some json array
saveNotification();
return someJsonArray;
}
function saveNotification(){
//some functionality
header('Content-Type: application/excel');
//save the file to .csv
}
If I comment out the 'header('Content-Type: application/excel');' line above then the service call does not return any error and returns proper json response. But if the line is retained then I get unacceptable content type error(application/excel) from the server.
Please let me know why is the content type set for the file header is being sent as unaaceptable content-header for service response? There is no connection between the file created and service response right?? I am not getting what the problem is.. Please help... Let me know If I have not made myself clear...

Unity WebGL/Parse Sign Up via REST API returns Unauthorized

I am working on integrating Parse with Unity for WebGL. Since the Parse plugin currently doesn't work with WebGL, I am forced to use the REST API (or edit the source code, which hasn't been working). Unfortunately, Parse doesn't have any documentation on how to use the REST API within the Unity/WebGL app, so I'm not even sure if I'm doing it right. Regardless, attempting to sign up with the code I posted below only gives me a "401 Unauthorized" error, at least in the Unity editor (I currently can't test to see if an actual build on my server will do anything different). I've also tried using the Client Key instead of the REST-API Key, but that had the same effect. Could someone give me pointers on where to go from here?
Here's my code:
string url = "https://api.parse.com/1/users";
WWWForm form = new WWWForm();
form.AddField("X-Parse-Application-Id", APP_ID);
form.AddField("X-Parse-REST-API-Key", REST_ID);
form.AddField("X-Parse-Revocable-Session", 1);
form.AddField("Content-Type", "application/json");
string newDataString = "{\"username\":\"" + email + "\",\"password\":\"" + password + "\",\"email\":\"" + email + "\"}";
WWW www = new WWW(url, System.Text.Encoding.UTF8.GetBytes(newDataString), form.headers);
The 401 error seems to point to a direction: the headers are not properly formatted. As an example, I was getting the same error because in the text field of an Authorization header there was a blank space between the = and " characters, like this:
token= "ajifidjoa...
So, first off, I suggest you to use something like Postman or any other REST client plugins for Chrome and test your call using them.
This way you should be able to understand better where the error is hidden.
Moreover, working with REST calls in Unity I found that a WebClient is way better for doing POST; sample code:
using (var client = new WebClient())
{
client.Headers[HttpRequestHeader.ContentType] = "application/json";
result = client.UploadString(url, "POST", json_string_to_post);
}

How to use Qooxdoo's Stores to request an ajax response with a POST?

In the tutorial enter link description here they only show this:
var url = "http://api.twitter.com/1/statuses/public_timeline.json";
this.__store = new qx.data.store.Jsonp(url, null, "callback");
But I would need to communicate with my own server, so I've made some changes: (url and Jsonp to Json)
var url = "http://127.0.0.1:8000/";
this.__store = new qx.data.store.Json(url);
But I would need to be able to send some information to the server when the store make the request like:
{serviceToUseOnServer: 'articles', argument1: 'xxx'}
This is like a POST request, but I don't really know how to send that data to the server using qooxdoo's Store models. Please don't tell me to use GET and encode all that data in an url.
You got the possibility to configure the request object used to send the data. Just add a delegate to the store and implement the configureRequest method [1].
[1] http://demo.qooxdoo.org/current/apiviewer/#qx.data.store.IStoreDelegate~configureRequest

Resources