I'm a Java Developer and couldn't find many resources to develop facebook apps on Java. Well I'm developing a Facebook app on Java which at some point, reads the inbox of a user. I was able to create a Login flow and get a long term access token. But as I'm very new to the JSON concepts, I could not able to parse the facebook response to get the required data.
I've read some tutorials and got to know basics of JSON and could able to write the code for parsing Simple JSON structures like:
{
"id": 1,
"firstname": "Brad",
"languages": [
{ "lang":"en" , "knowledge":"proficient" },
{ "lang":"fr" , "knowledge":"advanced" },
]
"job":{
"place":"Silicon Valley",
"name":"Microsoft",
} }
But, I was unable to parse the Facebook response as it looks so complex, and I have referred various places for any example or sample code to Parse the Facebook's response for /me/inbox request and couldn't find any.Here I'm looking for any sample code to parse the inbox JSON Object to get the required information for my App. Any effort is highly appreciated. Thank You.
Edit: I'm looking for a sample code in plain JSPs or Servelts.
Spring Social is your friend. Don't get bogged down in integrating with Spring Security (although there are a lot of examples) as the JavaScript login process will be sufficient to get an auth token for the user that you can then query Facebook's API with - just use Spring Social as a library to hide the complexity of the JSON and given you java objects to work with directly.
I ended up having to do it myself. The parent JSON element 'data' contained the data I was looking for. Then I used this tutorial to format it and display it in a Facebook-like way.
I had to actually pick out the data I actually needed. Hope this helps!
You have to use JSONObject and JSONArray, which you can get from getJSONObject() and getJSONArray(). Once you've gotten the JSONObject or JSONArray you need, use getJSONString() to get the desired value.
The tutorial mentioned above is for Android, but the general idea is still there. Let me know if you have any questions. I've done a bit in JSP and Java servlets as well.
Related
I am trying to use Google books API but for any request I receive totalItems = 0.
I've tried to send the request in chrome, for example:
https://www.googleapis.com/books/v1/volumes?q=flowers+inauthor:keyes&key=MY_KEY
Also I've tried the approach, described here:
https://github.com/google/google-api-java-client-samples/blob/master/books-cmdline-sample/src/main/java/com/google/api/services/samples/books/cmdline/BooksSample.java
And for any query with any parameters I always receive nothing:
{
"kind": "books#volumes",
"totalItems": 0
}
I generated key using developer console: https://console.developers.google.com and selected option Api Key.
I will appreciate any help with this issue.
Thanks in advance!
As I've understood, the problem is in my country(Belarus). Looks like Google Books APi doesn't work in Belarus. Problem can be fixed by using VPN.
How to get SMTP-ID in sendgrid API through json? Example :
In the API tutorial they have mentioned to execute
http(s)://username:password#domain/foo.php
and the result will be (in json):
"email": "john.doe#sendgrid.com",
"timestamp": 1337197600,
"smtp-id": "<4FB4041F.6080505#sendgrid.com>",
"event": "processed"
But actually we need the perfect url to get json.
for eg :
https://sendgrid.com/api/bounces.get.json
for bounce mails
similarly , is there anything to get the above sample json.
Thanks in advance..
If you send an Email to SendGrid through the Web API, you won't have an SMTP-ID. That will be generated by the SendGrid server that translates the API call to an SMTP object. So you're right, the SMTP-ID that comes back in the Event POST isn't helpful.
However, you can add Unique Args to your API call using the x-smtpapi argument in the mail.send call. This will let you define whatever tracking metric(s) you want to the message, and it will all come back on the Event POST.
If you are going to use Unique Args feature, please do remember that they will appear in the most Event notifications but not all of them. Please refer for the details to the sendgrid forum topics which include "missing unique_args" and similar. So, think twice before "building the entire infrastructure" around this feature like some of us did :(
I got my answer .
Actually we can try event API using a callback url, that receives POST request having every details about the email delivered, bounced in json format. Whenever some event is triggered we get a request from Sendgrid. Thats cool.
We can keep these details for further Filtering.
Anyway , thanks jacobmovingfwd
I am using XML-RPC and Jwordpress to view my site posts.
When I Use the following code:
Wordpress wp = new Wordpress(Username, Password, XMLRPCURL);
List<Page> recentPost = wp.getRecentPosts(10);
It returns only Drafts. How can I retrieve my Published Posts with JWordpress?
Best Thing to do is to Use Json API.
easily Install JSON on Your WordPress Site or Blog and with JSON Library for Java (Or Gson) You can get Posts and Many more stuff From Your site/Blog.
That's the Easiest way to do that I Think.
I need to use some from from a php web service which rendering its data by serializing json in java play framework 1.2.x. What i am doing just using play WS function. and i am getting data from that service. But when I try to get it with JSONObject it throws excepiton which is so normal, because the returned data does not look a json format well. Any body who knows any workarounds or solution would be appreciated.
HttpResponse htp = WS.url("http://www.geoplugin.net/php.gp?ip=78.171.90.49").get();
System.out.println(htp.getContentType()+"\n"+htp.getStatusText()+"\n"+htp.getString());
The returned data :
a:18:{s:17:"geoplugin_request";s:12:"78.171.90.49";s:16:"geoplugin_status";i:200;s:16:"geoplugin_credit";s:145:"Some of the returned data includes GeoLite data created by MaxMind, available from <a href=\'http://www.maxmind.com\'>http://www.maxmind.com</a>.";s:14:"geoplugin_city";s:8:"Istanbul";s:16:"geoplugin_region";s:8:"Istanbul";s:18:"geoplugin_areaCode";s:1:"0";s:17:"geoplugin_dmaCode";s:1:"0";s:21:"geoplugin_countryCode";s:2:"TR";s:21:"geoplugin_countryName";s:6:"Turkey";s:23:"geoplugin_continentCode";s:2:"EU";s:18:"geoplugin_latitude";s:7:"41.0186";s:19:"geoplugin_longitude";s:9:"28.964701";s:20:"geoplugin_regionCode";s:2:"34";s:20:"geoplugin_regionName";s:8:"Istanbul";s:22:"geoplugin_currencyCode";s:3:"TRY";s:24:"geoplugin_currencySymbol";s:15:"YTL";s:29:"geoplugin_currencySymbol_UTF8";s:3:"YTL";s:27:"geoplugin_currencyConverter";s:6:"2.2669";}
You are accessing the PHP endpoint. You need to hit this URL instead:
http://www.geoplugin.net/json.gp?ip=78.171.90.49
We currently handle the communication to/for backend api* and mobile (ios & android) apps.
For a stupid banner-like thingie, we should provide these apps with some HTML they'll render.
This is how it's done now:
String html ="<html>.....{somePlaceHolder}...</html>";
html = html.replace("{somePlaceHolder}", "We're good");
Gson gson = gsonBuilder.create();
gson.toJson(html);
This looks pretty bad to me. Wrapping html inside json is pretty useless.
I'm sure some templating engine can help us out here.
I was wondering what's the best way to do it.
I suppose I could have some HTML files that I could load up and then have my rest resource produce application/xhtml+xml or text/html this one time instead of json.
Anybody has suggestion on some best practices.
Thanks
*we use jax-rs/jersey
Not sure if I understand the whole problem correctly, but why do you want your RESTful service to return HTML in the first place.
I suppose the RESTful service should return JSON (or XML, for that matter) but the main point is, it should return only the actual data; no HTML at all, especially not HTML wrapped into JSON.
The application that calls the RESTful service should be responsible for the displaying of the data, that is wrapping the data into HTML.