Image compression when creating a photo with Facebook Graph API - facebook-graph-api

When I use the Graph API to upload a photo, as below, it works fine. Unfortunately the jpeg image quality on Facebook is significantly worse than the original photo's.
Is there a parameter I can add to maintain the quality?
var data = {};
data.url = photo_url;
data.message = "testing 123";
FB.api('/me/photos', 'post', data, function (response) {
console.log('response');
});

Related

Instagram Graph API - reels available but what is the format?

Facebook mentioned they're now making reels data available with the /insights endpoint, yay (see here )!
Although the article says they've updated their docs I don't see how it would be formatted, do we think the format will be like this?
insta_page_id/insights?metric=reels&period=lifetime
For a reels post in Instagram, you can try the following query in the Meta Graph API explorer(Assuming you have an app with required permissions):
[IGpost-id]/insights?metric=likes, comments, shares, plays,reach,saved,total_interactions
The above query should give you a response for these metric.
Currently I did not find any media_type as "reels". A reels media_type is still tagged as Video. Only way to identify if a post is a reel is through the permalink url which contains https://www.instagram.com/**reel**/XXXXXXX in it.
https://developers.facebook.com/docs/instagram-api/reference/ig-media/insights/
Thanks to #KristiLuna's comment above I was able to solve a similar problem.
Instagram reels are still identified by the Instagram Graph API as media_type: "VIDEO". The way to tell the difference between a feed video and a reel is by checking the media_product_type field on the Graph API.
My approach (to loop through an Instagram user's media):
fetch (`https://graph.facebook.com/v14.0/${ig-user-id}/media?fields=id,media_type,media_product_type`, {method: 'get'})
.then(response => response.json())
.then(data => {
let dataObject = data.data
dataObject.forEach((item, i) => {
if (dataObject[i].media_type === "VIDEO" && dataObject[i].media_product_type === "REELS") {
// do stuff
})
}
}

Upload photo to facebook fanpage appcelerator titanium

I have an app that lets me take a pic or choose from my gallery and upload it to my personal fb page.
How can I let it upload to my fanpage instead of my own page?
I use this for putting it in my page:
var data = {picture: image};
Titanium.Facebook.requestWithGraphPath('me/photos', data, "POST", function(e){
if(e.success) {
var d = Titanium.UI.createAlertDialog({
title: Titanium.App.Properties.getString("namn"),
message: 'Uploaded!',
buttonNames: ['Ok'],
});
d.show(); }
It wont just work to change the 'me/photos' to 'pageid/photos'.
What will I have to do to get it to work?
Thanx
As described under the photos secion in the Graph API Documentation for
Page
You should name the parameter source and not picture
Also, make sure you have the publish_stream and manage_pages permissions

Is it possible to post a status update and adding an image file with facebook graph API?

I want to post a status update to my feed and add a photo residing on disk, using the facebook graph api.
Is this possible or must I provide be a hyperlink address to the image?
I know it's possible to add a photo to an album using the Post object's source parameter but I'm looking for a way to do a status update with a image file attached.
It is definitely possible as we have published images directly to Albums and Walls using the Facebook C# API which posts to the graph API
We use the FacebookMediaObject to achieve this but I believe this simply creates the post form data required. Here is out code so you can take a look if it helps:
var facebookClient = new FacebookClient(entry.AccessToken);
var mediaObject = new FacebookMediaObject
{
FileName = filename,
ContentType = "image/jpeg"
};
var fileBytes = System.IO.File.ReadAllBytes(filename);
mediaObject.SetValue(fileBytes);
IDictionary<string, object> upload = new Dictionary<string, object>();
upload.Add("name", imagename);
upload.Add("message", message);
upload.Add("#file.jpg", mediaObject);
var result = facebookClient.Post("/" + albumId + "/photos", upload) as JsonObject;
Note the field name of "#file.jpg" which the mediaObject is assigned.
hope this helps.
Update
You may have to post the image to the users wall first and recieve an object ID which you can then reference in the post with the object_id field.
You can do it Without Using Facebook SDK. Here is the code to upload image via direct Facebook API.
var ImagePath = "480.jpg";
var caption = "Description of Photo";
string fullurl = string.Format("https://graph.facebook.com/me/photos?caption={0}&access_token={1}", System.Web.HttpUtility.UrlEncode(caption), accessToken);
WebClient client = new WebClient();
var returnVar = client.UploadFile(fullurl, ImagePath);

Facebook Graph API Photo Upload Image ID

brand new here.. I've looked everywhere, couldn't find an answer.. :/ Hopefully someone here can help me out. I'm using the graph api to upload a photo, and tag the user in it. This is currently working great. I would like to show the user the image, in the album, so I need the image id to generate the url. I cannot figure out how to do this!! Below are the lines of code that upload/tag the photo, to my app's album. What do I need to do to get this image id? Thanks a lot! -Tim
$user = $facebook->getUser();
function post_image($facebook, $user,
$image_path){
try{ $tag = array(
'tag_uid' => $facebook->getUser(),
'x' => 0,
'y' => 0
);
$tags[] = $tag;
$image = array(
'message'=> 'Your Banner Photo', 'tags' => $tags,
);
$facebook->setFileUploadSupport(true);
$image['image'] = '#'.realpath($image_path);
$facebook->api('/me/photos', 'POST', $image);
echo "";
return true;
}catch(FacebookApiException $e){
echo $e;
return false;
} }
Sadly, you have to do it as a separate query. You have to get the users galleries (first graph API call). then find the gallery ID you want and request the photos (second graph API call) then parse through the photos to find the one you want. Finally you have to request that photo.
-------------------Update:---------------------------
I'm not a very proficient php developer, but i use facebook api all the time with javascript or actionscript. The basic premise is to call the graph api, and it will return a json object of the result. Use getFile or Curl to load the graph api responses.
You can test your graph api calls here:
https://developers.facebook.com/tools/explorer/?method=GET&path=663032752
so try and walk that through from the graph api. Get the user galleries, then get the photos, then get the one you want.
To get the albums, call
"https://graph.facebook.com/me/albums?access_token="._accessToken;
To get the photos in an album you call it using:
https://graph.facebook.com/"._albumID."/photos?access_token="._accessToken;
And then to get the individual photo you would get the photo's ID property and call that.
sometihng like:
"https://graph.facebook.com/".your_photo_id;
I think using CURL is a good approach, but I'm weak on php, so use what you are comfortable with.
You have the photo ID in facebook API response, if it is uploaded successfully:
$result = $facebook->api('/me/photos', 'POST', $image);
echo $result['id'];

Facebook Media Attachment - fallback URL for 'music' type?

I'm using Facebook's Legacy REST API to publish MP3 media attachments to users' streams (as the new Graph API does not yet support audio). This renders the audio in Facebook's own media player as expected. However, because the player is a Flash component, it doesn't render on iOS devices and prompts for a Flash upgrade. I'd like to provide a fallback URL instead so the user can click through to an external site with an HTML5 audio player instead.
Is there a way of doing this? Supplying the href parameter in either the attachment object:
access_token = 1234567890.....,
format = 'json',
privacy = {
value: 'EVERYONE'
},
message = 'Message goes here...',
attachment = {
href: 'http://www.google.com',
media:[{
type:'mp3',
src:'http://www.looptvandfilm.com/blog/Radiohead - In Rainbows/01 - Radiohead - 15 Step.MP3',
title:'15 Step',
artist:'Radiohead',
album:'In Rainbows'
}]
}
or in the post object itself:
access_token = 1234567890.....,
format = 'json',
privacy = {
value: 'EVERYONE'
},
message = 'Message goes here...',
href: 'http://www.google.com',
attachment = {
media:[{
type:'mp3',
src:'http://www.looptvandfilm.com/blog/Radiohead - In Rainbows/01 - Radiohead - 15 Step.MP3',
title:'15 Step',
artist:'Radiohead',
album:'In Rainbows'
}]
}
does not seem to have any effect...
Am I therefore restricted to using the flash media type, supplying my own SWF player and image?
You can try the action_links array property on the post object to add a custom link for the user.
action_links = [("text":"alternate site link text here","href":"alternate url here"}]
You could try something like YepNope to test for iOS and load a different script based on the test.
yepnope({
test: '<test for iOS here>',
yep: '/scripts/scriptDefiningUrl.js',
nope: '/scripts/scriptDefiningFallbackUrl.js',
callback: function (url, result, key) {
alert('scripts loaded!');
}
});