I am trying to get the users' birthday via
$.getJSON("https:graph.facebook.com/me?fields=birthday&access_token="+accessToken, function(data) {
});
But unfortunately I have no idea on how to get the birthday itself because it gives me back this huge Object were I don't know how to handle it:
Could anyone please help me. I was looking at similar questions but unfortunately making the $.getJSON synchronous as suggested here is deprecated. The questions here and here did not really help either. Thanks in advance :)
To get the birthday in your code, you need navigate into Objects of your JSON data.
`$.getJSON("https://graph.facebook.com/me?fields=birthday&access_token="+accessToken, function(data) {
var birthday = data.birthday // This is your birthday
var id = data.id // This is your Fb ID
console.log('Hi! '+ id +'. Your birthday is '+ birthday)
});`
Related
I want to get details of a restaurant in Zomato. I have it's link as the input (https://www.zomato.com/mumbai/fantasy-the-cake-shop-kalyan?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1). By browsing the documentation of Zomato APIs, I didn't found a way to get it.
I tried searching for the restaurant using search API but it returns many results.
Any help will be appreciated
It's a two-step process:
Find out restaurant's city id, in your case, Mumbai's city id through the /cities API. It's a simple query search.
Use the city id from the above API call in the /search API, like, https://developers.zomato.com/api/v2.1/search?entity_type=city&entity_id=3&q=fantasy%20the%20cake%20shop%20kalyan
This would give all the basic information about a restaurant.
View the page's source and search for window.RES_ID
I had the same issue as you described. This Zomato's API approach is at least odd. It's almost immposible to GET any information about restaurant if you don't know res_id in advance and that's not possible to parse since Zomato will deny access.
This worked for me:
Obtain user-key from Zomato API Credentials (https://developers.zomato.com/api)
Search restaurant url via API (https://developers.zomato.com/api/v2.1/search?entity_id=84&entity_type=city&q=RESTAURANT_URL&category=7%2C9). The more specific you will be, the better results you'll get (This url is specified by city to Prague (ID = 84) and categories Daily menus (ID = 7) and Lunch (ID = 9). If there is possibility do specify city, category or cuisine, it helps, but should't be necessary. Don't forget to define GET method in headers.
Loop or filter through json results and search for the wanted url. You might need to use method valueOf() to search for the same url. Be careful, you might need to add "?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1" at the end of your wanted url so it has the same format. Check that through Zomato API Documentation page.
for (i in body.restaurants) {
var url_wanted = restaurant_url + '?utm_source=api_basic_user&utm_medium=api&utm_campaign=v2.1'
var url_in_json = body.restaurants[i].restaurant.url;
if (url_wanted.valueOf() == url_in_json.valueOf()) {
var restaurant_id = body.restaurants[i].restaurant.id;
}
console.log('Voala! We have res_id:' + restaurant_id);
}
There you have it. It could be easier though.
Hope it helps!
once you have the url of the rseraunt's page you can simply look for a javascript object attribute named "window.RES_ID" and further use it in the api call.
How to get the page fan's comments from facebook-api graph using koala gem
#user_graph = Koala::Facebook::API.new('XXXXXXXXXXXXX')
lists = #user_graph.get_object("#{pageid}/insights/page_storytellers")
but i want to get the all comments of the page fan's comments.
its giving null array results,
please anyone help me
Storytellers is a count of the unique people who created a story about your page post, it does not give you the full comment or info about the fan.
To get the comments on a page, you would have to first get a list of page posts, then query each post for comments.
You can get this info from any page, you do not need to have access to Insights.
For example:
page_info = #graph.get_object('nytimes')
pageid = page_info["id"]
fb_params = {
:fields => 'admin_creator,from,id,link,message,object_id,source,
status_type,story,story_tags,to,type,created_time,updated_time,
shares,likes.summary(true),comments.summary(true)',
:limit => 100,
:until => DateTime.now.at_end_of_day.to_i,
:since => DateTime.now.years_ago(5).to_i,
:metadata => 1
}
posts = #graph.get_connection(pageid, 'feed', fb_params)
If you include "comments.summary(true)" in the fields you request, you will get the first 25 comments on each post along with paging information (cursors, next and previous URLs).
Loop through each post and each post comment (and if you're up for it, comments on those comments), and you will have your result set.
If you prefer to skip writing the code, you could use Analytics Canvas to accomplish this task with a few clicks.
Full disclosure - I work with nModal on Analytics Canvas
You can do this with koala gem.
access_token = '#{access_token}'
#graph = Koala::Facebook::API.new(access_token)
page_name = '#{page_name}'
node_type = "posts"
# get posts with standard content
posts_standard = #graph.get_connections(page_name, node_type,limit: 5)
# get posts with replies
posts = #graph.get_connections(page_name, node_type, limit: 5,fields: "message,id,created_time,updated_time,likes.summary(true),shares,comments.fields(comments.fields(from,message),message,from),from")
I'm playing around w/ the /me/music.listens endpoint of Graph API and I have it working just fine. Except I can't seem to figure out how to get actual artist info to come back. I see the song and even the album (though that seems a little inconsistent too). But never any artist info.
Check the developer explorer here: https://developers.facebook.com/tools/explorer/?method=GET&path=me%2Fmusic.listens
No artist info. Is this just not returned? I can't see how to specify this in a fields param list. FB's documentation of the actions is spotty at best so I figured I'd try here.
Thanks!
I've figured out a work around. It doesn't look like Facebook actually returns artist info. So you have to use the Spotify Lookup Service (http://developer.spotify.com/technologies/web-api/lookup/).
To break it down a little further, you start by pulling the music.listens feed from FB and you'll get info that looks like:
(
[song] => Array
(
[id] => 381659191902248
[url] => http://open.spotify.com/track/**2Vv27Gc5k5GgGW9jgtj1CS**
[type] => music.song
[title] => Follow Through
)
)
From there, you need to grab the bolded track ID.
Lastly, fetch the song metadata with this call to Spotify: http://ws.spotify.com/lookup/1/.json?uri=spotify:track:2Vv27Gc5k5GgGW9jgtj1CS
You'll be returned the album name, artist info, etc.
If someone knows a better way, lemme know!
You can retrieve artists informations on graph API with the song id :
https://graph.facebook.com/song_id?fields=data{musician}
ex : https://graph.facebook.com/697975930266172?fields=data{musician}
Old question I know, but you can retrieve related information such as both the song title and artist title in the same request using Graph API's 'field expansion'.
For example - Last 10 songs
me?fields=music.listens.limit(10){data{song{title,id},musician{id,title}}}
To retrieve more information from either the song or musician entities just tweak the fields requested.
Note, this requires user_actions.music permission
I manage to sent a photo from my server to a users album on facebook.
But this photo is not automaticly seen on his wall. And specifically it is not seen as a big photo, like how photos from albums are shown on a wall.
So I suppose I have to do a second request to tell facebook to put the photo on the wall.
I have these 2 requests:
$ret_obj = $facebook->api('/me/photos', 'POST',
array(
'source' => '#/var/www/cover/test.jpg',
'message' => $_POST['msg']
)
);
This returns for example:
[id] => 358313274248558 [post_id] => 100001736648729_358281023575116
$ret_obj = $facebook->api('/me/feed', 'POST',
array(
'message' => $_POST['msg'],
'object_attachment' => $ret_obj['id']
)
);
I have tried for the 'object_attachment' 358313274238558, 100001796648729_358281027575116 and 358281027575116. But facebook tells me that those are not correct.
So how on earth can we add a photo to a wall, which we just put in an album, and which we want to show in a large format (not as a little thumbnail).
If there is another way, without using albums, that is fine with me.
Please help. I know there have been a few questions already about photo uploads to facebook here on stackoverflow, I think I have read them all about 10 times already. It seems there is no answer yet. Somebody said we could post to /me/links but facebook doesn't seem to be able to handle links like http(s)://www.facebook.com/photo.php?fbid=358309510905631 anymore.
I have changed the ids in this post so they are not linked to actual stuff, they are here as examples.
Thanks
edit:
Ok, it seems a post of an image to an album is also a post of a big image to the wall IF the user allows the app to do public stuff. Because I was developing, I told the app to not do public stuff and only show stuff to me personally.
So there is no need to do 2 requests, just adding a photo to the album is enough to have it appear big on the users wall IF the user allows app activity to be public.
It is still somewhat confusing that a second request seems unable to also add the foto in a large size to the wall.
I'm trying to update the status of a user and then immediately retweet it. I can't figure out how to get the ID of the status I just submitted though.
Any help would be greatly appreciated.
Are you doing a
twitter.updateStatus("Some String");
If so, this returns a Status, which has a getId() method
myStatus = twitter.updateStatus("Some String");
myId = myStatus.getId();
If not, please post your code.