Upload image to meta ads using marketing api - facebook

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:

Related

Set a playlist picture using the Deezer JS API

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}

Can you retrieve facebook photos in Unity?

Is there anyway to retrieve photos that are not the profile picture on Unity through the facebook api? or any other way?
1. Easiest
Use www class to fetch the image texture.
string link = https://graph.facebook.com/v2.1/" + friendID + "/picture?width=50&height=50&redirect=true;
WWW pic = new WWW (link);
yield return pic;
if (pic.error == null)
{
go.renderer.material.mainTexture = pic.texture;
}
where friendID is your facebook id. Here you can pass the id for any of your friends.
width and height to specify what dimension do you want the image to be.
2. A bit complex but useful in long run
link to pass to www class
string link = https://graph.facebook.com/v2.1/" + friendID + "/picture?width=50&height=50&redirect=false;
the difference in this method is that you are now not redirecting to the cdn permanent link.
this will give you a json file. Now you can parse the json file to get the actual link.
use this link again with www class to get the actual image
benefits of using this method.
You can save the image once and next time just ping for permanent link only.. if they match then don't fetch image again.
You're in luck. Facebook themselves have made a tutorial for Unity, which is a small game using Facebook's profile pictures. Here is a link to it.
Yes you can. Not sure what platform are you using.
You can use Facebook official SDK from here
https://developers.facebook.com/docs/unity
Authorise your platform, facebook will give you a token.
Then you can call graph API to get whatever you need.
For Example:
https://developers.facebook.com/tools/explorer/145634995501895/?method=GET&path=me%3Ffields%3Did%2Cname%2Cphotos&version=v2.2&

How to post an image to a Facebook wall using Grails

I am using the grails facebook-sdk plugin to connect and post to facebook.
To publish a message to a user's wall I use:
def publishMessageResponse = facebookClient.publish("me/feed", [message:"RestFB test"])
This works fine, but I want to post an image to a specific album of the user. The documentation says that it should work with:
def publishPhotoResponse = facebookClient.publishFile("me/photos", [message, "Test cat"], "/cat.png")
But I alway get a "File not found" error. The image I have is stored in a data base and can be retrieved by getting the url to the image.
Knowing the url of the image, how can I post this image to a specific user photo album? How can I create a new Album?
I haven't used the facebook-sdk but I would assume that the issue is that it can't find the file '/cat.png' relative to the location of you're project. You'll need to provide valid and accessible file path.
You could confirm this by doing something like this before publishFile...
assert new File("/cat.png").exists(), "File does not exist!"
UPDATE:
Here is an example of converting a url to a file. This may not be the ideal solution if there are other options besides using an actual file.
def someUrl = "http://www.google.com/images/logo.gif";
def file = File.createTempFile("facebookUpload",".temp").withOutputStream { out ->
out << new URL(someUrl).openStream()
}
file.deleteOnExit();
def publishPhotoResponse = facebookClient.publishFile("me/photos", [message, "Test cat"], file)

cannot get image info using https://graph.facebook.com/<photo_id>

The API always return false, without any detailed information.
Then same even when using the photo IDs of my own photos.
However, the photo ID listed in the API document (the Coca Cola one) works without problems...
Your call to FB is correct i.e.
https://graph.facebook.com/PHOTO_ID + accesstoken
will return a JSON response with info about your image and urls to download the image in different sizes.
Most likely reason for your problem is you haven't requested the "user_photos" permission from the app user.

Getting Actual Facebook and Twitter Profile Image URLS for Flex Security Policy

I'm trying to display the profile images from both facebook and twitter. For facebook, the URLs I'm receiving are something like this (not actual urls):
http://graph.facebook.com/965412145/picture
Which is then redirected to the 'actual' url like this:
http://profile.ak.fbcdn.net/hprofile-ak-snc4/370471_9631690_1796253478_r.jpg
I'm also doing this with twitter, with the same issue (redirected url).
So, when I load the image, it loads fine. But when I close the container that the image is in, then I get the security sandbox violation.
I can get this all to work if I add the URL from the 'actual' image url like this:
request = new URLRequest("http://profile.ak.fbcdn.net");
loader = new Loader();
context = new LoaderContext();
context.checkPolicyFile = true;
loader.load(request, context);
However, at run time, I do not actually know what the 'actual' image url is, so I can't hard-code that domain in (nor do I want to).
Is there a way to get the actual url (from within flex) of the image so that I can add the correct domain to the loadercontext?
Any ideas are appreciated!
If I understand correctly, your problem is that you're trying to load an image from a URL that redirects to another source. You need to know what the redirected URL is, so you can load a policy file that allow manipulation of image bytes.
If I've understood correctly, you need to detect the redirected URL by listening for the COMPLETE event (or an error event), then reference the LoaderInfo.url property. This property will reflect the end URL in the event of redirects. For example, you would have code like this in the listener:
var ldr:LoaderInfo = event.target as LoaderInfo;
var url:String;
try
{
url = ldr.url;
// Split off URL base, load policy file, etc here
}
catch (e:Error)
{
// Unable to detect final URL due to error.
}