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)
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:
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&
I'm trying to post an item to a user's news feed with an image on my own site. I get the "FBCDN image is not allowed in stream" error which normally occurs when someone tries to include an image that is on Facebook's server, however the image I'm including is on my own server.
var imgSrc = $('.final-badge .badge-background img').attr('src'),
badgeUrl = $('#largeCrestView').val();
var obj = {
method: 'feed',
//Will need to be retrieved from a hidden text field in ASP environment
link: badgeUrl,
picture: imgSrc,
name: 'All hail my Coat of Charms',
caption: captionText,
description: ''
};
This is my code. The imgSrc variable contains a direct link to an image stored locally on my server. The URL is an absolute path as well.
An ideas what I'm doing wrong here?
I actually worked it out. It was that the location of the image, as I've been informed, was not publicly accessible. Now that It's external it works fine.
I am developing a Facebook Application an i wanna send a video file from myServer to Facebbok User`s Timeline. This is the page with the explanation http://developers.facebook.com/blog/post/515/#video_upload but its a PHP code.
My app is on Grails, and im looking in HTTBuilder class but can't find a way to do this.
Do someone know how to do it?
If isnt possible to do this with HTTPBuilder, in my app, i am using Spring Social Facebook Plugin on Grais
I found the interface MediaOperations but i dont know how to use this interface and use the method postVideo to upload a Video.
Thanks!
Will try to help a bit. You may use MediaOperations interface for this operation. Spring Social Facebook Plugin configures a service called Facebook for you. You can use it via dependency injection.
Here is a simple code example:
import org.springframework.social.facebook.api.Facebook
class FacebookService {
Facebook facebook
def uploadVideo(String videoFileName, String title, String description) {
try {
def videoResource = new FileSystemResource(videoFileName)
facebook.mediaOperations().postVideo(videoResource, title, description)
return true
}
catch (Exception e) {
log.error("Error to upload video to facebook", e)
return false
}
}
}
The video is loaded from the file in the FS by specified file path/name from videoFileName variable. This means, user need to upload the video first, and code should save it to some file in FS first, then upload. Usually this is the best case, as video files are large. Maybe there is a sense to upload the video to facebook in separate thread and don't give the user to wait.
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.
}