I am trying to use the Spotify Web Playback SDK to play full songs in a browser. Following the docs I am still confused of how to actually play a song using this API. I can control playback/volume etc of a song thats already being played using my account, but there are no endpoints in the API to give it a track payload and have it play back that song.
Any help is appreciated.
You need to use the Spotify Connect Web API (docs here: https://beta.developer.spotify.com/documentation/web-api/reference/player/)
Using the device_id you get from the Web Playback SDK, simply make a call to /me/player/play. Here's how that would look with AJAX:
$.ajax({
url: "https://api.spotify.com/v1/me/player/play?device_id=" + device_id,
type: "PUT",
data: '{"uris": ["spotify:track:5ya2gsaIhTkAuWYEMB0nw5"]}',
beforeSend: function(xhr){xhr.setRequestHeader('Authorization', 'Bearer ' + _token );},
success: function(data) {
console.log(data)
}
});
Check out this simple Glitch example to get started: https://glitch.com/edit/#!/spotify-web-playback
Related
I'm trying to use the pull approach for vimeo api uploading, but the vimeo UI shows the films 'uploading' forever, and none of the metadata I've included in the post request makes it to vimeo either.
My request looke like this (i've redacted some of it). The signedURL works and has an expiry of 1 day.
{
path: '/users/xxxxx/videos',
query: {
upload: {
approach: 'pull',
size: 27759876,
link: 'https://storage.googleapis.com/xxxxxx/xxxxxxx%2F0079e513eb90623236b9fce0ebdc5a29%2Ffilm%2F0079e513eb90623236b9fce0ebdc5a29.m4v?GoogleAccessId=xxxxxxxxxxxxxxxxxxxx&Expires=1599054191&Signature=jLEDJ8iNaRC4eDn37DHoCilhKMmDk04h17Vu%2FbDUJbNFxdbjR9CowMQWdn95MdrX....etc'
},
name: 'xxxx',
description: 'xxxxxxx',
privacy: {
download: true,
embed: 'private',
comments: 'nobody',
view: 'anybody'
}
},
method: 'post'
}
and the response back from vimeo appears valid - with lots of vimeo metadata and a vimeo id for the uploaded film.
Looking at the nodejs api on github I only see tus upload approach examples - so now I'm wondering if the client actually supports the pull approach. Has anyone been able to get it to work?
You'll want to use the params property instead of query; using params will put your metadata into the request body instead of providing it as a query parameter.
params is mentioned in the docs as part of the upload method, but it should be used with the request method when making a POST or PATCH.
I think your example request is fine, just swap params for query
https://github.com/vimeo/vimeo.js#uploading-videos
https://github.com/vimeo/vimeo.js/blob/c7a1a16c1805539a00bc37d661b81c10e2108a75/example/upload.js#L63
I need to download all the revisions of a google doc with the Drive API using nodejs but I don't understand how to authorize the request for the export links. Once I get the export link for each revision I call:
var options = {
url: 'https://docs.google.com/feeds/download/documents/export/Export?id=1DRl6rbcVuuLVyb_WlhBLiYiCByWcS2bKGlLIsn7E8_8&revision=1&exportFormat=txt', //example link
method: 'GET',
headers: {
Authorization: `Bearer ${jwToken}`,
},
}
request(options).pipe(fs.createWriteStream(mydownloadfilename));
where the "jwToken" is the token I use to get the revisions list so I guess it should be still valid. However, with this I get the 401-Unauthorized page. What am I doing wrong?
Thanks
According to the Drive API v3 documentation:
Revisions for Google Docs, Sheets, and Slides can't be downloaded.
So essentially, if the actual revision you want to retrieve is the file itself, then the method above is the correct one.
As for the authorization part, you will need to perform the Node.js Quickstart from here and follow the steps explained there.
Since you want to export the file, you will just need to modify the code and add this part:
function downloadDoc() {
var fileId = 'ID_OF_THE_DOC';
var dest = fs.createWriteStream('DESTINATION_OF_THE_OUTPUT_STREAM');
drive.files.export({
fileId: fileId,
mimeType: 'application/vnd.google-apps.document'
})
.on('end', function () {
console.log('Done');
})
.on('error', function (err) {
console.log('Error during download', err);
})
.pipe(dest);
}
Reference
Drive API v3 - Manage Revisions;
Drive API v3 - Files:export;
Drive API v3 - Quickstart;
Drive API v3 - Download a document.
I am facing this same problem. The solution is to use
OAUTH2 authorization for a user that has Edit or Owner permissions for a file
Get an access token that expires quickly
call the V2 URI (V3 does not work) for the file/rev to get "export links" 3) Call the correct export link for your format type
then you will get a randomized temporary redirect link from Google that you can then call to get the binary stream.
This is a great starting point for C# .NET -- windows oauth console app, if you want working code to do steps 1 and 2. I posted a working v2 code function here that you can put into the console app example.
I'm launching a Google Hangout from my webapp. I want to pass some data from my webapp to the Hangout window, and then back to my webapp. I am currently able to pass data back to my server with an AJAX post from the Hangout window, however, I then have to send this to the launching browser from my server.
Is there a direct line of communication from my launching app to the Google Hangouts app? I'm pretty new to webdev, so this might be an obvious question.
Well the thing you are trying to achieve here to get and post data from your hangout app and web application server, and you are already posting the data from hangout app to your webserver.You can write a route in your application the one running on your web server to return the data you are trying to fetch and again in your hangout app can make a ajax get action to get the required data in form of JSON or any required format, and grap the result in success callback of ajax.
example call:-
$.ajax({
type : "GET",
url:'/your_route_on_web_application/to_return_the_requested_data',
data : { any_data_you_want_to_pass: random_data},
dataType : 'json',
success : function(data) {
// do anything you want to with the received data
}
});
I have a nodejs (+express + mongodb,gridstore) backend, and want to upload a photo to a facebook album.
I came across 2 methods. the first ( https://developers.facebook.com/blog/post/526/ ) needs to get the full url resource of my picture, which I don't have as it is data that I pull from gridstore,
and the second ( https://developers.facebook.com/docs/reference/api/album/ ) is very poorly documented, via the Graph API, where I can't figure out what my request should look like. (the form-data, what fields should it have, how to convert my data blob\stream from gridstore to it)
Here is what I currently have, and doesn't work:
facebook.uploadPhoto = function (token, albumId, photo, callback) {
var fb = fermata.json('https://graph.facebook.com/' + albumId);
fb.photos({access_token:token}).post({'Content-Type':"multipart/form-data"}, {source:{data:photo}}, callback);
};
Any help would be much appreciated
There is a good chance the file is not properly serialized. Fermata will take a node File buffer via data. Have you tried passing that instead?
fs.readFile("/path/to/photo.jpg", function (err, data) {
fermata.json("https://graph.facebook.com/graph/api").post({"Content-Type":"multipart/form-data"}, {fileField: {data:data, name:"", type:""} }, callback);
});
Adding your access token etc..
I solved this problem by using a simple POST to the facebook graph API using the poster module.
var options = {
uploadUrl: 'https://graph.facebook.com/'+user+'/photos?access_token='+accessToken,
method: 'POST',
fileId: 'source',
fields: {'message':''} // Additional fields according to graph API
};
var fileName = ''; // Local or remote url where to find the image
poster.post(fileName, options, function(err, data) {
if (err) {
//Something went wrong
} else {
// Everything ok
}
});
Honestly, I've got limited experience working with the Facebook graph API and mostly using PHP and Java.
Here is some streams that you might find helpful:
Upload Photo To Album with Facebook's Graph API
Facebook Graph API - upload photo using JavaScript
Basically, I recommend you punt a little in your implementation and code it in the following way:
Create a REST web service function call in Node.js to output a single image from gridstore using an internal UID.
Code your uploadToFacebook function to use an image URL that calls the REST web service function.
Basically, this would allow you to validate the image output by pointing your browser to the REST web service and avoid any blob\stream conversions inside your uploadToFacebook function. I'm assuming you store the image in gridstore vs. mongodb.
hope that helps...
I want to run Spotify searches from within a Spotify app (to find tracks for an artist, for which I do not have a Spotify URI, only the name).
I have not found functionality in the App API to run searches. An alternative is to talk to ws.spotify.com to get to Spotify's search, but these web services do not support jsonp which is required for their use in a Spotify app.
What are my options?
You can use sp.core.search
sp.core.search("query",
{onSuccess: function(result) {
// parse result
}
}
);
sp.core.getMetadata if you have the uri
sp.core.getMetadata("uri", {
onSuccess: function(data){
console.debug(data);
},
onFailure: function(){
//...
},
});
This is not the finest way to solve your problem. There is a direct API for searching within your app. See Juan's solution.
But you could also talk to ws.spotify.com directly when you add the domain to your app's manifest.json.
"RequiredPermissions": ["http://ws.spotify.com" ]
e.g. http://ws.spotify.com/search/1/track.json?q=kaizers+orchestra, see their
Developer Site. The response contains the header "Access-Control-Allow-Origin: *", so you should be able to query from within your app.