Get friends read articles with Facebook JS API - javascript

i'd like to know how to fetch articles that friends have read from a Facebook app. I use the following query to get articles that I have read:
/me/news.reads
But i want all the articles that friends have read, is that possible?

It is not an apt solution but you can do is loop through facebook id's of your friends and for each friend's Id get all the news read as /$friend_id/news:reads
I dont think there is any direct api function to get action performed by friends.

Try this
FB.api('/me/friends', { 'fields' : 'name,news.reads.limit(10)' }, function (data) {
// if(!data || data.error) { }
// console.log(data);
});
You can omit the limit if you like, or add more fields. Of course this would also work as a GET request to: http://graph.facebook.com/me/friends?fields=name,news.reads.limit(10)&access_token=XXXX

Related

Search for artist id by name

I am delving into spotify and javascript is not my main programming language so I managed to get some snippets together from a code that uses ajax (which I would rather not use) but still it returns nothing so I am wondering if some more experienced people out there could help me get started with a template to call the api.
My goal for this test is to search an artist name and get the first result (I expect many names will return multiple artists)
Most of what is in the documentation is curl and I didn't find the demos very helpful.
What I have so far is something like this:
function getArtistName (artistName) {
var artistID;
var searchArtists = function (query) {
$.ajax({
url: 'https://api.spotify.com/v1/search',
data: {
q: query,
type: 'artist',
'accessToken': 'BQBvW70gHJ20Flc8cHErqg8s72bfTePbssblED-gpEuHFr_Yezesbthok8qaKBmjzo2WjWo9J7ZcTpSwvV8MZ_cW_E7UkrG_HF2R6gFQcqfdupgYGmoYsdRdt1q3tq2NU3pPgauuzmFLkUpdAuNp3shdVXJz2SzvnA',
'query': artistName,
limit: '1.'
},
success: function (response) {
//resultsPlaceholder.innerHTML = template(response);
}
});
};
console.log(searchArtists);
return artistID;
}
Some points of confusion:
The key seems to expire. I have a client ID on my profile but I am not sure where I can generate this token other than the "try it out" demo on the site.
What does this actually return, an ID or a JSON?
Here is a demo app that searches tracks using Node.js, or server-side Javascript: https://spotify-quicksearch.glitch.me/
If you click the "Remix this on Glitch" link on the page, you can see and edit the source.
The call to the API is made in server.js. First, we set the client ID and client secret, which are from the dashboard, as you've noted. In this example, we use those to get an access token using the Client Credentials Flow. You can read about all the authentication flows here: https://beta.developer.spotify.com/documentation/general/guides/authorization-guide/
This particular example uses an API wrapper called spotify-web-api-node, which just makes it easier to interact with the API through Javascript functions. To search for artists instead, just change searchTracks to searchArtists.
To answer your second question - all calls to the Spotify API return JSON. You can see the format of the full JSON response here: https://beta.developer.spotify.com/documentation/web-api/reference/search/search/. Roughly, it looks like this:
artists: {
items: [
{
id: <id>,
name: <name>,
...
}
...
]
}
To get the ID from the JSON, you need to parse the JSON object. You can see how I do this in the example in line 21 of client.js. You can modify that code to get just the ID of the first artist like this:
data.artists.items[0].id
Update: made an example that should be even more relevant:
https://spotify-search-artist.glitch.me/

Facebook: How to get any pages total likes, ratings?

I would like to get any facebook page's total likes, ratings, etc...
I have created a developer account
What I tried:
- Created an app for this.
- Tried to fetch this information using AppID & AppSecret
- Tried Using access token
I have also done R&D on google and tried many examples but not getting a correct solution which I want.
Pls help me to solve this.
Thanks.
Edit (taken from comment by author):
I tried this example but for every page it requires pageaccesstoken
FB.api('/{pagename}?fields=ratings', function (response) {
Data = response.name; //alert(Data);
if (response.error) {
alert(response.error.message);
}
}, { access_token: "xxxx|yyyy" });
You can get the current likes of a Page with a simple App Access Token:
/[page-id]?fields=fan_count&access_token=[App-Token]
For the ratings of a Page, you need to use a Page Token instead:
/[page-id]/ratings&access_token=[Page-Token]
More information about Tokens and how to get them:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/

Soundcloud SDK - load track from url

So I did a tutorial on Soundcloud SDK through CodeAcademy here and wanted to take the knowledge I learned from that and put it on Codepen. But I want to use a different track than the one they use in this tutorial - specifically this song https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download.
I read that /resolve was a good approach to get the trackid but it's not working. I get 403 Forbidden in the console.
SC.get('/resolve/?url=https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download&client_id=3596a42d6242b9c1ee76740a7771d33a', function(track) {
console.log(track); // returns null
});
Here is my codepen. Please help me load this track for my basic SoundCloud SDK audio player. Thanks
Your code is correct and even works with some tracks, for example the ones from the documentation.
You're encountering a problem that I found personally should be emphasized in their documentation. The API access for this track has been disabled (even if the widget is enabled), therefore your have not right to query this track using the API and it returns a 403 Forbidden HTTP status code.
This is described in the Linked Services part of the SoundCloud terms of use:
You can limit and restrict the availability of certain of Your Content to other users of the Platform, and to users of Linked Services, at any time using the permissions tab in the track edit section for each sound you upload, subject to the provisions of the Disclaimer section below.
You can check in your code if any error like this one was encountered while fetching the track informations and depending on the success or failure, continue with the correct action:
var clientId = 'CLIENT_ID';
SC.initialize({
client_id: clientId
});
var songUrl = 'https://soundcloud.com/hardwell/coldplay-sky-full-of-stars-hardwell-remix-download';
SC.get('/resolve?url=' + songUrl + '&client_id=' + clientId, function(data, error) {
if (error === null) {
console.log('Do something like playing the song.');
} else {
console.log('Print an error message?');
}
});

Facebook javascript API get users photos one at the time

Hello i am trying to get the users tagged photos one at the time with javascript.
Here is how i call it:
FB.api('/me?fields=name,picture.type(large),photos.limit(2).type(tagged)', function(response) {
play(response.name, response.picture.data.url, response.photos.data.source);
....
And how i use them:
use: {url: "some url....", params: ['name','fb','photo1', 'photo2']},
The thing is that when i call this i get "Cannot read property 'data' of undefined "
on the photos.limit(2).type(tagged)
The other things work great. Name and profile pic.
Any ideas?
Perhaps i need to sort the results from photos.limit(2).type(tagged) or something but i have no clue o how to do that...
Any help will be awesome.
Thanx
Sounds like you aren't getting any data from the photos endpoint.
Ensure that you have user_photos permission in
FB.login(function(response) {
// handle the response
}, {scope: 'user_photos'});

Simple jQuery getJSON Call to Twitter

I have read many Twitter & jQuery questions on here but none seem to answer my question. I am simply trying to grab 5 "tweets" from a public user. I am not doing anything with the data at this step, but my callback function never fires.
$.getJSON("https://api.twitter.com/1.1/statuses/user_timeline.json?callback=?",
{
screen_name: 'dojo',
count: '5'
},
function (data) {
alert("IT WORKED!");
});
Here is the same code on jsFiddle
Thank you for your help
That isn't going to work because Twitter has now required that you authenticate in order to fetch tweets for a given user.
Reference: https://dev.twitter.com/docs/api/1.1/get/statuses/user_timeline Look at 'Authentication' info.
You'll want to use a library to help get an oauth signature and make the request.

Categories