Facebook API for extracting basic(Public) profile info of a person - facebook

Actually I want to extract basic(Public Profile) information of a person on Facebook by it's name or email-ID without any type of authentication. So, can anyone tell me the detailed procedure how i can acheive this using Java Programming and i want the result in XML format

https://graph.facebook.com/4
Will give you a result similar to -
{
"id": "4",
"name": "Mark Zuckerberg",
"first_name": "Mark",
"last_name": "Zuckerberg",
"link": "http://www.facebook.com/zuck",
"username": "zuck",
"gender": "male",
"locale": "en_US"
}
That will give you all the public information about a user. The response you get is a JSON object. If you want it in XML you'll have to manually convert it.
Beaware that not all USER_ID's will return information. It all depends on the user's privacy settings.
I have no knowledge of JAVA so I can't give you and code samples, but you can make a simple HTTP request to that URL using whatever methods you feel comfortable with...

Related

What's the RESTful way to return metadata on a collection of resources?

Say I have a REST API for accessing user notifications. I have an endpoint for getting all notifications:
GET https://server:443/api/notifications
Which returns the following response:
[
{
"status": "unread",
"_id": "5db8228d710ab4b1e33f19b2",
"title": "Some title",
"time": "2019-10-29T11:29:17.402Z",
"details": "Some details...",
"user": "user1"
},
{
"status": "unread",
"_id": "5db8228d710ab4b1e33f19b3",
"title": "Some title",
"time": "2019-10-29T11:29:17.411Z",
"details": "Some other details",
"user": "user2"
},
]
Now, I'd like to also be able to retrieve the amount of notifications for each user in a single request, for which the response will be something like:
[
{
"user": "user1",
"count": 1
},
{
"user": "user2",
"count": 1
},
]
What would be the best way, in terms of REST conventions, to do that?
What would be the best way, in terms of REST conventions, to do that?
REST really doesn't answer that. REST tells you that you have resources, but it doesn't actually offer any opinion on where the "boundaries" of your resources should be.
Again, think "web pages". You could add your summary to the web page that describes notifications, and that would be fine. Or you could decide that the notifications are described on one web page, and the summary on a different web page, and that would be fine.
What REST does tell you is that caching is important; so if you think the cache controls for summary data should be different from notification data, then you want to be thinking about separating that data into a different resource. If you think the summary data and the notification data needs to be synchronized, then its more likely that they belong as part of the same resource.
Of course, there's nothing in REST that says you can't have multiple resources that return the "same" data.
If you wanted the summary to be part of the notifications resource, and also wanted that information to be independently identifiable, then you would use a fragment to describe the summary "sub-resource"; perhaps https://server:443/api/notifications#summary.

Can someone explain, what does the webhook do in api.ai?

I am new to api.ai. I want to send data to the web server and receive it and then give it to the users? From the documentation that I read, I understood that I have to use a webhook. But I am not sure how will api.ai send and receive the data?
Can the webhook be developed in any language?
The webhook is a web service that you implement in any language and on any platform, with an HTTP (must be https for ghome) and JSON interface, that fullfils (in their lingo) a user intent.
API.AI matches a user utterance to an intent (which then suggests entity values and a response) and they pass these in the call to your web service. You do whatever processing you need - your domain logic - and then return a speech response for the user and optionally some API.AI contexts.
You can read more about it (and about slot filling fulfillment which is a little different) here.
You can visualize the working of a webhook like a block where data request comes in JSON format somewhat like this:
{
"id": "7aef9329-4a32-4d59-b661-8bf380a0f35b",
"timestamp": "2017-06-07T05:36:12.641Z",
"lang": "en",
"result": {
"source": "agent",
"resolvedQuery": "hi",
"action": "order.pizza",
"actionIncomplete": true,
"parameters": {
"address": "",
"crust": "",
"sauce": "",
"size": "",
"time": "",
"topping": "",
"type": ""
}
}
}
and another json file is returned to it according to the prescribed settings.

Facebook API not working sometime for some URL

I'm getting number of shares and comment of blog posts using facebook graph api for my blog, but sometimes it do not return shares and comment.
Following URL is not giving number of share and comments.
http://graph.facebook.com/?id=http://www.lehedonist.com/jeans-is-the-new-whiskey-2001
BUT it is working for this URL:
Example: http://graph.facebook.com/?id=http://www.lehedonist.com/spring-slam-fashion-war-ss16-1965
I somehow wonder why it's even working to request these URLs without an access token to be honest.
See
https://developers.facebook.com/docs/graph-api/reference/v2.5/url
It only gives a result if there no version info in the URL. To do this in the v2.5 way properly, you'd have to use
https://graph.facebook.com/v2.5/?access_token={access_token}&fields=id,og_object,share&id=http://www.lehedonist.com/spring-slam-fashion-war-ss16-1965
where {access_token} is an actual access token.
Results will look like
{
"id": "http://www.lehedonist.com/spring-slam-fashion-war-ss16-1965",
"og_object": {
"id": "987675524635070",
"description": "Not your usual fashion post, we decode styles best suited to your personality and what should you be sporting next summer",
"title": "Spring Summer 16 fashion: The clash of fashion personalities",
"type": "article",
"updated_time": "2015-10-08T11:24:32+0000",
"url": "http://www.lehedonist.com/spring-slam-fashion-war-ss16-1965"
},
"share": {
"comment_count": 2,
"share_count": 81
}
}

How can I expose statistics about resources through a RESTful API?

I'm building an API for my web app and have got as far as exposing all the resources my app uses, e.g. /users, /roles, /posts etc with no problem.
I'm now stuck on how to expose statistics about some of these resources in a RESTful way. It doesn't seem right to have a statistics resource, as GET /statistics/1 could be anything, and the results will likely change each request, as the stats are real-time, so it will not be cacheable.
Background:
For each of the /users in the system, the app periodically queries Steam's API for the /games they are playing, and the /servers they are playing it on, and stores this information along with a timestamp in the /states resource.
This information is aggregated to show a tally of the most popular games and servers on the /statistics/games/current-usage and statistics/servers/current-usage standard HTML pages. Illustrative screenshots: servers, games (taken at different times).
EDIT: Sample data for the basic resources
"state": {
"id": 292002,
"user_id": 135,
"game_id": 24663,
"server_id": 135,
"created_at":"2014-06-22 21:12:03"
},
"user": {
"id": 112,
"username": "ilumos",
"steam_id_64": "76561197970613738"
},
"server": {
"id": 135,
"application_id": 24663,
"name": null,
"address": "192.168.241.65",
"port": "0"
},
"game": {
"id": 24663,
"name": "DEFCON",
"steam_app_id": 1520
}
EDIT 2: Does REST permit endpoints that use a timestamp as the resource identifier? e.g:
GET /statistics/1403681498/games to get a response like this:
[
"game": {
"id": 123,
"name": "DEFCON",
"users": [
{
"id": 7654,
"username": "daryl",
"server": {
"id": 127,
"ip": "123.123.123.123",
"port": "27960"
}
},
{
"id": 135,
"username": "ilumos"
},
]
}
]
You have a variety of not-wholly-unreasonable options.
You can
include statistics with each response. Will all clients want
statistics? Are there a lot of statistics? Maybe something like GET /games?orderBy=numPlayers-&offset=0&limit=10 would work if all you're tracking is number of players.
have a /statistics/{statisticId} endpoint. This is not inherently unRESTful.
have a /games/{gameId}/statistics endpoint.
have a /statistics/games/{gameId} endpoint.
Really, there's no way for us to tell you what the best way is to implement this because we don't have enough information.
I'm going to go with creating a usage resosuce as all of these statistics will be the usage of other resources, either "right now" or at a historic point in time.
My URIs will look like this:
GET /usage/{resource-name}/{resource-id}
GET /usage/games/ collection of games in use right now (with user totals)
GET /usage/servers/ collection of servers in use right now
GET /usage/games/?timestamp=1234567890 collection of games in use at {timestamp}
GET /usage/games/1 usage of game with id 1 right now
GET /usage/games/1?timestamp=1234567890 usage of game with id 1 at {timestamp}
GET /usage/games/?user_id=123 usage of game with id 1 filtered to show only user with id 123
And in future I can extend the resource to for example return usage for electricity usage
GET /usage/phases/ collection of phases in use right now (with power draw totals)
GET /usage/phases/1 usage of phase with id 1 right now
GET /usage/phases/?timestamp=1234567890 collection of phases in use at {timestsamp} (with power draw totals)
Unless there's something inhernatly un-RESTful about this it seems to be the most fitting way of exposing this info.

How to construct a permalink for objects returned by Facebook's new Graph API?

Facebook Graph API allows getting Facebook objects like posts, videos etc in JSON from. Here is an example of a post: (taken from the documentation):
{
"id": "719323658_129694190395214",
"from": {
"name": "Rabia Yalcinkaya",
"id": "719323658"
},
"message": "COK MUHTESEM!!!",
"picture": "http://external.ak.fbcdn.net/safe_image.php?d=41762b7121ee68754ebea48dee4568aa&w=130&h=130&url=http%3A%2F%2Fats.vimeo.com%2F192%2F882%2F19288238_200.jpg",
"link": "http://vimeo.com/5646785",
"source": "http://vimeo.com/moogaloop.swf?clip_id=5646785",
"name": "Watermelon carving",
"caption": "vimeo.com",
"description": "Me carving a watermelon.",
"icon": "http://static.ak.fbcdn.net/rsrc.php/z9XZ8/hash/976ulj6z.gif",
"type": "video",
"created_time": "2010-06-23T10:58:17+0000",
"updated_time": "2010-06-23T10:58:17+0000",
"likes": 1
},
How does one construct a url which allows you to link back to the original video (or other types) on Bret's wall on Facebook? something in the form of
http://www.facebook.com/<USER_ID>/video/<VIDEO_ID>
Thanks,
Boaz
in the actions field there is the link field (for each available action) which happens to contain the permalink to the given post. However be sure to inspect this before relying on it - it might change. I've only used it with "comment" and "like".
Apart from that you'd have to construct it manually. For users that have their username set (i.e. their profile is accessible via facebook.com/username, it works with:
http://facebook.com/USERID/posts/POSTID
For everything else:
http://www.facebook.com/permalink.php?id=USERID&v=wall&story_fbid=POSTID
Source: http://forum.developers.facebook.net/viewtopic.php?pid=316384
Note that the POSTID is in the form USERID_POSTID, so you'd have to strip the first part.