My client would like to create playlists on Deezer, and also add their own pictures against their creations.
I have a simple playlist creation call, using the Deezer JS SDK:
playlistObj = // already created object with title,
// description, images array and
// array of Deezer track IDs
DZ.api('user/me/playlists', 'POST',
// fields object
{
title : playlistObj.name,
picture_small: playlistObj.images[2].url,
picture_medium: playlistObj.images[1].url,
picture_big: playlistObj.images[0].url,
},
function (response) {
DZ.api('playlist/'+response.id+'/tracks', 'POST',
{ songs: playlistObj.tracks },
function (playlistTracksResponse) {
console.log(playlistTracksResponse); // true
}
);
}
);
The playlist and tracks create fine and I can see them on my account. However, the picture urls I'm setting and passing in the fields object and not being used by Deezer. Do the images need to be in a specific format? Do they need to be in a specific size? Can you only set images with a specific account type?
The documentation doesn't suggest that picture uploading is precluded, and I've tried various combinations of images from google image searches, of jpg, png and of a variety of sizes, including 200x200px as I can see on their site.
Any help?
I'm sorry, what you're trying to do isn't supported by the API. When you create a playlist, the only field you can set is title.
Call https://api.deezer.com/infos, you will get a JSon with un upload token.
Send a POST as form_data with a key « file » with your image content on https://upload.deezer.com/playlist/{playlistId}?access_token={accessToken}&upload_token={uploadToken}
Related
I am trying to upload an image, get the image hash for use in creating an adcreative using meta marketing api on google colab, but i keep getting an empty list, don't know why that keeps happening.
i have properly authenticated and i am able to post ad campaigns, adsets remotely but i am unable to upload and image or view list of existing images/hash
path = '/content/drive/Shareddrives/Design/sampleimage.png'
image = AdImage('act_5**********')
image[AdImage.Field.filename] = path
image.remote_create()
image_hash = image[AdImage.Field.hash]
print(image)
even when i try to read the existing adimages i also get an empty lsit.
FacebookAdsApi.init(my_app_id, my_app_secret, my_access_token)
my_account = AdAccount('act_5**********')
fields = ['id','hash','name','original_height','original_width']
images = my_account.get_ad_images(fields=fields)
images
try uploading your images as .bmp, .jpeg, or .gif:
I am attempting to display the latest post from a public Facebook page on a website using the graph API.
Using the following URL, I am able to get the latest posts data:
https://graph.facebook.com/MYPAGENAME/posts?access_token=MYACCESSTOKEN
Which returns:
{
"data": [
{
"story": "MYPAGENAME added a new photo.",
"created_time": "2017-08-20T19:00:00+0000",
"id": "MYID"
}
...
The post in question displays on the Facebook page with a photo included, but there is not 'photo' object (or anything similar) returned in the API data. How do I access the picture URL for this post? Thanks in advance.
This request will fetch posts and the media information for the first image for each post.
/posts?fields=attachments{media}?access_token=YOUR_ACCESS_TOKEN
Sometimes posts contain multiple images. If you'd like to support that you need to fetch the subattachments also:
/posts?fields=attachments{subattachments{media}}?access_token=YOUR_ACCESS_TOKEN
Note that this method usually only provides image URLs that are up to 720px wide. If you want higher resolution imagery, you need to access data[0].attachments.data[0].subattachments.data[0].target.id to get the actual image ID which you can then use to perform an additional query /IMAGE_ID_HERE?fields=images to obtain the higher resolution image. Increment the numbers to get additional posts and images inside each post.
Is there a way to get the public link of a Facebook Album through the Facebook API (graph/fql) that can be shared with those who are not on Facebook?
This Album is not publicly accessible. It is restricted by the share permissions on the album set by the user. But I am looking for a way to generate the public link of this restricted album so whoever is sent this link can view the album unconditionally.
I know this is possible through the Share Album feature on the Facebook website through the Share Dialog: You can send this album to friends or relatives by giving them a link.
I couldn't find a way to to this in the Graph API.
EDIT: I'm talking about the public link that is available through this feature on facebook: facebook.com/help/124590517619792
You didn't provide an example or test case, nor any API code to work with. I'll use the following links for Facebook User Name Hostess as an example (long live Twinkies!).:
Main: https://www.facebook.com/Hostess
Photo Album: https://www.facebook.com/Hostess/photos_albums
First, we will need the Facebook User Number.
You can perform a GET request or type this into the browser:
Facebook User Info: http://graph.facebook.com/Hostess
To continue with this example, we will use the Facebook Number provided by the previous step:
Facebook ID: 145369525544570
Is there a way to get the public link of a Facebook Album through the
Facebook API (graph/fql) that can be shared with those who are not on
Facebook?
Yes there's a way! This link will provide you with json results for all albums, in this case 6:
Facebook Albums via json: http://graph.facebook.com/145369525544570/albums
To limit the returned results, you can use ?limit=1 (where 1 is the amount of albums returned):
Facebook Album (1) via json: http://graph.facebook.com/145369525544570/albums?limit=1
This Album is not publicly accessible. It is restricted by the share
permissions on the album set by the user. But I am looking for a way
to generate the public link of this restricted album so whoever is
sent this link can view the album unconditionally.
Your out of luck and there isn't a way. However, you don't have to be a Facebook Member to view the images in the Album. Using the json data from the previous step works when the Album is made public. Just use a simple GET request:
jsFiddle DEMO: Facebook Albums Links from Facebook ID
// Console log messages are provided, activate your browsers console.
$.ajax({
url: 'http://graph.facebook.com/145369525544570/albums',
dataType: "json",
success: function(yourVar) {
// Make sure the request, 1 json object, was returned.
if (yourVar) {
console.log('This is the jQuery Object received. Click on it to explore contents');
console.log(yourVar);
// This will parse the Objects received in 'data' variable.
// Having said that, it's coincidental the data the wrapped in a 'data' name.
$(yourVar.data).each(function(index) {
// Only process Objects that have valid Album links.
// Having said that, only Photo Albums are returned in initial data, not Video Albums.
if(this.link){
// Display in console the jQuery zero indexed number
console.info('Album Index object: ' + index);
//
// Display in HTML via append, the same information.
$('body').append('<b>Album Index Object: </b>' + index + '<br />');
// Display in console the Album Names available
console.info('Name: ' + this.name);
//
// Display in HTML via append, the same information.
$('body').append('<b>Name: </b>' + this.name + '<br />');
// Display in console the Album Name Url;
console.log('Url: ' + this.link);
//
// Display in HTML via append, the same information.
$('body').append('<b>Url: </b>' + this.link + '<br />');
// Display in console dashed lines before next item is shown.
console.log('-------');
//
// Display in HTML via append, the same information.
$('body').append('<hr><br /><br />');
}
});
} else {
console.log('Was data expected? Check your jQuery or JavaScript for errors.');
}
}
});
// Power-Tip!
// You can also use .ajax() with a YQL Rest Query url.
// See YQL Console with Rest Statement at:
// http://developer.yahoo.com/yql/console/?q=SELECT%20data.link%20FROM%20json%20WHERE%20url%3D%22https%3A%2F%2Fgraph.facebook.com%2F145369525544570%2Falbums%22&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys
// As seen there, the data.link is providing just the links.
// Change data.link to * to see all data nodes available in json tree.
// That being said, your .ajax() url for above is at the bottom: The Rest Query.
In Detail: Why it can't be done. (otherwise it's a security issue!!!)
Facebook Settings for Photos and Albums:
When I share something, how do I choose who can see it?
The above Facebook documentation states that if a Album is set to Private via Only Me, then it will only be available to you, even though you may have a shareable link for it.
To demonstrate that the Album/Photos is indeed locked and not shareable, here is an actual live test using Yahoo! Query Language to perform a request on a locked photo album:
Feel free to click the image to visit the above YQL Statement.
To be sure, the above example in itself shows that the link is not the issue, it's the content that is really the subject, as that's the item locked for which a Facebook Token key is required.
I'm creating a Facebook Flash app and I'm having trouble uploading a photo to Facebook with myself or friends tagged. I am stuck at this for a whole time now and couldn't find the solution
First of all here are the permissons I want the app to have.
ExternalInterface.call("redirect","appId","user_birthday,read_stream,publish_stream,user_photos,friends_photos","http://apps.facebook.com/appName");
Here is what I do to upload the photo to Facebook without tags (this works):
var params:Object = {name: 'My Card', image:card, message: 'Greetings from Barcelona' , fileName:'Card'};
Facebook.api('me/photos', onSaveToPhotoAlbumComplete, params);
But when I want to add tags of friends or myself it doesn't work, Here is what I did (In this case I only want to tag myself in the picture):
var params:Object = {name: 'Rosada Face-It', image:card, message:message, fileName:'Face It!', tags:[{"id":myId,"x":50,"y":50}]};
Facebook.api('me/photos', onSaveToPhotoAlbumComplete, params);
I also tried it with quotes and "tag_uid" instead of "id" but that is not the problem I think:
tags:'[{"tag_uid":"'+ editorModel.tag1 +'","x":"50","y":"50"}]'
If somebody could help?
Looking at the API I think a seperate call may be needed to add tags
http://developers.facebook.com/docs/reference/api/photo/
I think to create a tag you need to have the PHOTO_ID and then do a POST to PHOTO_ID/tags
var params:Object = {{"to":myId, "x":50, "y":50}]};
Facebook.api(photoId +"/tags", onPhotoTagged, params);
Is there a way to know if a user uploaded an image to the profile or it has the default user picture of Facebook via FQL or somthing else?
If a user doesn't have a photo then the is_silhouette field will be true when you request the user object with the "photo" field specified.
Example request:
https://graph.facebook.com/username?fields=picture
Response:
{
"id": "100002095576350",
"picture": {
"data": {
"url": "http://profile.ak.fbcdn.net/static-ak/rsrc.php/v2/yo/r/UlIqmHJn-SK.gif",
"is_silhouette": true
}
}
}
Quick, dirty PHP function:
function facebook_user_has_photo($username_or_id){
$request = file_get_contents('https://graph.facebook.com/'.$username_or_id.'?fields=picture');
if($request):
$user = json_decode($request);
if($user && !$user->picture->data->is_silhouette) return true;
endif;
return false;
}
You can use the Python script below (as not mentioned any programming language) to make it work.
urllib.urlopen('https://graph.facebook.com/<PROFILE_ID>/picture?access_token=%s' % access_token).geturl()
This will provide you a Facebook profile photo URL. If that URL contains <PROFILE_ID> then it uploads an image. Else the default Facebook image is uploaded.
For example, if uploaded image:
http://profile.ak.fbcdn.net/hprofile-ak-snc4/195361_<PROFILE_ID>_4179703_q.jpg
else:
For male:
http://b.static.ak.fbcdn.net/rsrc.php/v1/yo/r/UlIqmHJn-SK.gif
For female:
https://fbcdn-profile-a.akamaihd.net/static-ak/rsrc.php/v1/y9/r/IB7NOFmPw2a.gif
I hope this helps.
From my experiments with the Facebook API, it appears one has to actually get the picture in order to tell whether it's a static default one or not.
At the time of writing, it appears that all uploaded photos on Facebook are converted to JPEG, while the static default pictures are in the GIF format. (BTW, this is not consistent with some thumbnail sizes).
Looking for specific GIF file or a specific URL path is not reliable (note that there are CDN URLs involved, and that there are different static files for male and female). Assuming Facebook doesn't re-encode their entire profiles photos database, I suppose looking for a GIF is reliable enough.
Here's a sample PHP function to do this. I've tested it successfully with my 120 Facebook friends, and it seems to do the job.
public static function hasProfilePicture($fbuid)
{
/* Really stupid method to test if Facebook user has real profile picture
* based on Facebook returning a GIF image when you request a large photo.
* Use with care - for every profile there's an outgoing request! */
$r = get_headers("http://graph.facebook.com/$fbuid/picture?type=square");
return !array_search("Content-Type: image/gif",$r);
}