Facebook Event Json Mesage- how can i get it? - json

I would like to ask if someone know how to grab a facebook event json message. It doesnt matter if it has to happen programatically. I just want to be able to read the message one way or another.
thanks in advance.
P.s. Maybe an awful question but here you go !!!

I once had to code a small chunk of code to parse a json-encapsulated message. However recently I found out there's a handy solution for it if you use Java
Resty is a small, convenient library
to talk to RESTful services from Java.
It’s surprisingly complex to do the
simplest HTTP calls with the standard
Java library. Resty hopes to change
that.
http://beders.github.com/Resty/Resty/Overview.html
Resty r = new Resty();
Object name = r.json("http://ws.geonames.org
/postalCodeLookupJSON?postalcode=66780&country=DE")
.get("postalcodes[0].placeName");
Just import a small jar lib and you'll be surprised. I currently use this class for getting info from url API.

Related

Parsing last message from Pushbullet using Selenium

I'm trying to parse the last received message from Pushbullet. I'm currently doing it using Clicks, which means that I do every single clicks, sendkeys and all the rest needed actions automatically. In other words it is just a simulation of the user. One of the biggest con of the method is that whenever xpath or a class or id of the element changes which I'm aiming with Selenium, whole cycle fails and the test case can not proceed operating.
I want to change the way I'm doing. Particularly, I want to send a json request to Pushbullet API and then get the response in return.
I just couldn't decide from where and how to start doing.
Could you guys please tell me the way from where should I start and what are the steps that needs to be covered in order to finally reach the finish line?
Thank you in advance.
I noticed that this question is tagged under Selenium, but in your question, you express interest in switching to an API approach. I will try to provide some advice to you on this.
Selenium Approach
You mention that you tests are brittle, and if anything changes then they fail. This is usually the case with UI tests. If you would like to stick with the Selenium approach, I can try to help you write more robust locators for your WebElements that will not break constantly.
API Approach
You will need to start with the Pushbullet API documentation -- https://docs.pushbullet.com/
To get messages, it looks like you will want to use the chat endpoint -- a sample request looks like this: https://api.pushbullet.com/v2/chats, plus authentication.
Once you fetch the chat objects, you will need to write your own logic to parse each chat object and fetch the most recent message from there.
Depending on what language you are using, you will need to install a REST client package onto your project. I use C#, so RestSharp is the client I like to use.
I recommend installing a REST client interface, such as Postman, to start practicing your API calls. Once you get your API calls working in Postman, you can start writing code to make these API calls.
What other questions do you have about this?

Non-standard JSON and Azure Logic Apps

I have an API that produces JSON like this:
)]}',
{
//JSON DATA
}
The //JSON DATA is valid JSON, but the )]}', up top is not.
When I try to GET this data via a Logic App, I get:
BadRequest. Http request failed: the content was not a valid JSON.
So, a few related questions:
1) Can I tell the logic app to return the invalid JSON anyway?
2) How can debug the issue better? I happen to know that the response is invalid, but what if I didn't? Can I see the raw data somewhere?
3) This is all done via the Azure web portal. Are there better tools? Visual Studio?
I should also mention that if I call a route on the same API that returns XML instead of JSON, then the Logic App works fine. So it definitely doesn't like the JSON response in particular.
Thanks!
First of all, please do not post three questions as a single question.
Question 1). The best thing you can do is make the API return a valid JSON object. This is good for million reasons. Here're a few:
it's pretty much a standard (either valid JSON or XML -- yeah, old school way);
therefore, no users of this API (including you) will need to struggle and guess what's going on and why;
your Logic App's step will just work without adding extra complexity;
you will make this world and your karma better.
If API-side changes are not within your reach, I don't think you can do much. If you're lucky and the HTTP action is successful (Status Code 2xx), you can try to use a Query Action with a function that truncates the first characters. It will look something like this (I don't know the exact syntax): #Substring(body('myHttpGet'), 4, length(body('myHttpGet')) - 4) where myHttpGet is the id of the Http Get action.
However, once again, if possible, I strongly recommend fixing up the API which is the root cause of the problem, instead of dealing with garbage response after that.
UPDATE Another thing you can do is wrap the dirty API. For example, you could create a trivial Azure Function that invokes the API you don't directly control, and sanitizes the response for you consumption requirements. This Azure Function function should be easy to call from the Logic App. It costs almost nothing (unless we're talking millions of requests/month). The only drawback here is the increasing latency, which may be not an issue at all -- test it and see whether it adds less than 100ms or so... Oh, and don't forget to file a ticket with the API owner, they make our world a bad place!
Question 2) In Azure Logic App web UI you can Look into the execution details and the error will definitely be there.
Question 3) You're asking for a tool recommendation which is by definition a highly subjective thing and is off-topic on StackOverflow.
TL/DR: The other app is not producing valid JSON.
Meaning, this is not a problem for you to solve. The other app has to return valid JSON if the owner claims it should.
If they cannot or will not produce valid JSON, then the first thing you need to do is inform your management that you will have to spend a lot of extra time accommodating their non-standard format.

WSo2 API Manager 1.8.0 - JSON parsing issue

I am new to wso2 API Manager, trying to set it up expose my plain HTTP POST back end calls as a REST API. I am sure this is not a new pattern that I am trying to achieve here. The requirement is to convert the JSON data coming in (has array structures) into the HTTP URL query string parameters.
After some research through the documentation and other posts on this forum, decided to go with the script mediator that would parse the JSON data and convert it to a string that can be appended to the endpoint URL. Some how I am not able to achieve this.
I have followed the following post that seems to be very straight forward. As the original poster suggested, I am also not able to use getPayloadJSON() method. Even have trouble using the work around suggested there due to JSON.parse() not working.
Link
Also, this approach of editing the service bus configuration from source view does not sound like the correct option. Is there another elegant solution to achieve this? Thanks for the help in advance.
I was able to get both methods working by using an external script instead of the inline java script. Thanks

Json parsing in IBM Worklight

I am trying to achieve something like which is mentioned in this link
but i don't know whereto write the parsing code. I tried to write it in new method and added the method in "my adapter.xml" but nothing happens. I even don't know how to log in IBM WorkLight. I used WL.logger(some) but its throwing error that "Logger can not be called on an object".
Any help would be appreciated. Thanks in advance.!
In most cases you don't need to manually parse responses because WL adapter framework will do this for you. Anything you retrieve via WL.Server.invokeHttp API will be parsed to JSON automatically unless you specify returnedContentType:"plain". In case you DO need to manually parse JSON you can use JSON.parse() and JSON.stringify() APIs.
Server side logging is achieved via WL.Logger.debug/error/info etc. You can get more info about it here
You don't have to parse JSON data, there are libraries in Javascript to do that. Try JSON.parse(). You should learning how to write adapters and invoking them from clients. The Getting Started modules are a good place to start, specifically Module 4 in your case.

Sample Facebook classes for c#?

Like some of you allready know, i'm trying to get data from facebook in JSON format and view it in a gridview or something like that.
With some help of StackOverflow, i managed to get the data i needed.
Now I want to make a List of my json string.
Do I have to make a class for every JSON object in my json string? Like the class user, location, work_info, education_info?
Is there any place where i can find the c# class files for all the facebook objects?
I think there are a lot of programers who use these classes, does everyone write the same classes again?
I have added a reference to the facebook(.web) sdk. But I don't know if I can use this for my problem.
I hope you can help me,
Thx!
The reason why there are not strongly typed classes for Facebook Schema in the Facebook C# SDK is that they usually change very frecuently. That's why the developers of the Facebook C# SDK decided not to go that way:
http://ntotten.com/2010/08/dynamic-csharp-with-frequently-changing-web-services/
http://ntotten.com/2010/09/dynamic-objects-and-the-facebook-c-sdk/
Although if read the Roadmap: http://facebooksdk.codeplex.com/wikipage?title=Road%20Map you will see that there are plans for a strongly typed Graph API objects but it looks like there is no much activity in that area.
If you need strongly typed classes for your app, you will probably only use a few that are easy to create.