How to post a gallery-image on a users wall - facebook

Our app uses the PHP- aswell as the JS-SDK of Facebook. We are able to access the users-images and the images of his friends thru both sdks. The upload of photos into user-albums works aswell.
The user currently selects one of his images which gets manipulated on our server and uploaded to Facebook into the album it came from. That part works. We now want to post that uploaded image onto the users wall. Facebook itself generates a post on the users feed about newly uploaded images (can be disabled on the uploading request) but those posts are not customizable. The standard facebook-post request requires an url to the optional photo. The documentaton states that it is not allowed to link to images from the facebook content delivery-network (which has been confirmed by the graph api as it throws an appropriate error).
Is it possible to create a standard wall-post that contains a gallery-image somehow? Ideally it would use the gallery-popup but that is clearly super-nice-to-have.
An externally hosted copy is an (unwanted) workaround that we already know. Reuploading the image is an option as long as it does not show up in the gallery twice.

Simple solution :
Get a tinyurl for you fbcdn'ed picture through tinyurl api:
Example with url from above :
http://tinyurl.com/api-create.php?url=http://a4.sphotos.ak.fbcdn.net/hphotos-ak-snc3/13943_196960329960_683709960_2997879_7206516_n.jpg
Returns :
http://tinyurl.com/3ta96kh
Then use this url as the "picture", I tried it here and it works ! : http://jsfiddle.net/dwarfy/VYAeD/27/
There was another solution here but It seems facebook corrected it and it still says the error with facebook CDN when I post using https://graph.facebook.com/PICTURE_ID as picture instead of the FBCDN image url.
I think it's the best solution ...
My example doesn't use the link parameter but you could set it to the gallery image ...

Indeed you can't post to users' walls image saved on fb BUT also you don't have to save it physically on you server. if you want to post an image, for example:
http://a4.sphotos.ak.fbcdn.net/hphotos-ak-snc3/13943_196960329960_683709960_2997879_7206516_n.jpg
facebook as you know will not accept this. but ther is no problem to post something like this: http://yourserver.com/script.php?image=a4.sphotos.ak.fbcdn.net/hphotos-ak-snc3/13943_196960329960_683709960_2997879_7206516_n.jpg (without http:// -- its important, if you include http:// facebook will find out what's going - and we don't want it:)
script.php is a php file on your server that do this:
<?
$url = "http://".$_GET['image'];
header('Content-type: image/jpeg');
echo file_get_contents($url);
?>
or something like this:
<?
$url = "http://".$_GET['image'];
$image = imagecreatefromjpeg($url);
//some image modifications here//
header('Content-type: image/jpeg');
echo imagejpeg($image, null, 100);
?>
you can also add an database with urls and post something like this: http://yourserver.com/script.php?imageid=ID hiding all images' real paths.
If you want to save on traffic after publishing images on walls just redirect:
<?
//if published then just redirect
$url = "http://".$_GET['image'];
header('Location: '.$url); die();
?>

You have to make the copy of that image otherwise there is no way you can use this image in standard post dialog.
Use PHP function
copy()
I know you are looking for any other alternative but to create a spare image on your server or any other server is the only solution.

Related

Unable to render OneNote image resource after appending preAuthenticated=true option in OneNote api call

https://github.com/microsoftgraph/microsoft-graph-docs/issues/2624
I am experience the issue as the above.
I am trying to save the content of a page with a reference to an image by calling https://graph.microsoft.com/v1.0/users/{userId}/onenote/pages/{pageId}/content?preAuthenticated=true
Per this - Downloading one note page with image content as HTML
By appending "?preAuthenticated=true" when you do the fetch, it will make the image public.
But when I tried to render the html, it's giving me "Failed to load resource: the server responded with a status of 401 (Unauthorized)".
It appears that something is wrong with the official document: Get OneNote content and structure with Microsoft Graph.
We can see that the service root URL is https://graph.microsoft.com/{version}/{location}/onenote/.
But in any of the samples on this page, the URL is still https://www.onenote.com/api/v1.0/me/notes.
Currently, when you add ?preAuthenticated=true you will get such a URL for a image on this page:
https://graph.microsoft.com/v1.0/users('{userID}')/onenote/resources/{resourceID}/content?publicAuth=true&mimeType=image/png
But when you try to access it in a browser, you will get 401 error Access token is empty.
A workaround is to modify the URL to:
https://www.onenote.com/api/v1.0/resources/{resourceID}/content?publicAuth=true&mimeType=image/png
Then you will get the image.
https://github.com/microsoftgraph/microsoft-graph-docs/pull/4339/files
I think they removed the support for it.
Bit of off topic, but I figured out how to get the image to render.
https://learn.microsoft.com/en-us/graph/api/resource-get?view=graph-rest-1.0&tabs=http
When you call /onenote/pages/{id}/content, the image has a reference to a source like this
src="https://graph.microsoft.com/v1.0/users({userId})/onenote/resources/{resourceId}/$value" along with data-src-type="image/jpeg"
do a get request to this endpoint and you'll the image binary, convert the binary to base64, and then just render the html by replacing the src with base64.

How to get big picture from feed (now)? Api has been changed

I just noticed that Facebook has been changed on retrieving the picture url from feed. Usually I replace _s with _n and I get the "normal" image.
Now I get somthings like this:
https://scontent-b.xx.fbcdn.net/hphotos-xfp1/v/t1.0-9/p130x130/10527490_10152146397901714_1807442783989783336_n.jpg?oh=a4035ad97f2fa1f9a5cf1612e2195662&oe=542053AD
which is only "small". How can I get the bigger one?
You should ideally be using graph api to get pictures.
If however, you need to get bigger image from these type of url links.
First retreive their final url after 302 redirect :
h ttps://scontent-b.xx.fbcdn.net/hphotos-xfp1/v/t1.0-9/p130x130/10527490_10152146397901714_1807442783989783336_n.jpg?oh=a4035ad97f2fa1f9a5cf1612e2195662&oe=542053AD
Remove the bold part, and you will get the original image:
https://scontent-b.xx.fbcdn.net/hphotos-xfp1/10527490_10152146397901714_1807442783989783336_n.jpg?oh=a4035ad97f2fa1f9a5cf1612e2195662&oe=542053AD
EDIT : This method does not work anymore,graph api is the best way to go.

Facebook could not post to wall facebook error 1367001

This self answer is the result of agonizing over the deprecated facebook sharer url based api, which kept refusing to post the URL I had setup through the sharer URL format. The resultant response was the following no matter what privacy setting I set:
{
"__ar":1,
"error":1367001,
"errorSummary":"Could not post to Wall",
"errorDescription":"The message could not be posted to this Wall.",
"payload":null,
"bootloadable":{},
"ixData":[]
}
My mess of code. (Yes it breaks every convention known to web development and yes I inherited this code.)
<?php
$url = urlencode(Domain::getDomain()."/".$details['urlname']);
$title=urlencode($details['name']);
$summary=$details['name'];
$image=urlencode(constant('BASE_IMAGES').'/'.$details['gallery']['listing'][0]['thumb']['src']);
?>
<a onClick="window.open('http://www.facebook.com/sharer.php?s=100&p[title]=<?php echo $title;?>&p[summary]=<?php echo $summary;?>&p[url]=<?php echo $url; ?>&p[images][0]=<?php echo $image;?>','sharer','toolbar=0,status=0,width=548,height=325'); return false" href="javascript: void(0)"><img src="/site/images/icon-facebook.png" alt="Facebook" border="0"></a>
The official question is as follows: Why does the sharer method of sharing links in facebook result in this error?
For my case, this was because I had not included the fully qualified URL including the protocol. My PHP generated URL was a mess of concatenation and did not include the protocol. After adding it, the post went through.
I had to change the second line listed above to
$url = urlencode('http://'.Domain::getDomain()."/".$details['urlname']);
There could be more reasons why Facebook throws this 1367001 Error, but this is at least one thing to check.
Yes, Please start your Url with http://
eg : http://www.google.com
May be there might be Url validations been performed at their (FB's)end hence start with Protocol name and end with domain name (com,co.in, ie)
This fixed my issue :)

Facebook debugger: Clear whole site cache

I am aware that Facebook caches the Like data for specific pages on your site once they're visited for the first time, and that entering the url into the debugger page clears the cache. However, we've now improved our Facebook descriptions/images/etc and we need to flush the cache for the entire site (about 300 pages).
Is there a simple way to do this, or if we need to write a routine to correct them one by one, what would be the best way to achieve this?
Is there a simple way to do this,
Not as simple as a button that clears the cache for a whole domain, no.
or if we need to write a routine to correct them one by one, what would be the best way to achieve this?
You can get an Open Graph URL re-scraped by making a POST request to:
https://graph.facebook.com/?id=<URL>&scrape=true&access_token=<app_access_token>
So you’ll have to do that in a loop for your 300 objects. But don’t do it too fast, otherwise you might hit your app rate limit – try to leave a few seconds between the requests, according to a recent discussion in the FB developers group that should work fine. (And don’t forget to URL-encode the <URL> value properly before inserting it into the API request URL.)
The simple solution in wordpress, go to permalinks and change the permalinks and use a custom permalink, in my case I just added an underscore so did this...
/_%postname%/
Facebook then has no info on the (now) new urls so they scrape it all fresh.
I was looking for this same answer and all the answers were super complicated for me as a non coder.
Turned out there is a very simple answer and I came up with it all by myself :) .
I have a wordpress website that with a variety of plugins I've bulk uploaded over 4,000 images that created 4,000 posts.
The problem was I uploaded them and then tried setting up the facebook share plugins before sorting the og:meta tag issue so the total 4,000 posts were scraped by FB with no og:meta so when I then added them it made no difference. The fb debugger could not be used as I had over 4k posts.
I must admit I'm a bit excited, for many years I have got helpfull answers from google searches sending me to this forum. Often the suggestions I found were well over my head as I'm not a coder, I'm a "copy paster".
I'm so happy to be able to give back to this great forum and help someone else out :)
Well i also got the same scenario and used hack and it works but obviously as #Cbroe mentioned in his answer that the API call has some limitation with rate limiting so i guess you should take care of it in my case i only have 100 URLs to re-scrape.
So here is the solution:
$xml = file_get_contents('http://example.com/post-sitemap.xml'); // <-- Because i have a wordpress site which has sitemap.
$xml = simplexml_load_string($xml); // Load it as XML
$applicationAccessToken = 'YourToken'; // Application Access Token You can get it from https://developers.facebook.com/tools/explorer/
$urls = [];
foreach($xml->url as $url) {
$urls[] = $url->loc; // Get URLS from site map to our new Array
}
$file = fopen("response.data", "a+"); // Write API response to another file so later we can debug it.
foreach($urls as $url) {
echo "\033[Sending URL for Scrape $url \n";
$data = file_get_contents('https://graph.facebook.com/?id='.$url.'&scrape=true&access_token='.$applicationAccessToken);
fwrite($file, $data . "\n"); //Put Response in file
sleep(5); // Sleep for 5 seconds!
}
fclose($file); // Close File as all the urls is scraped.
echo "Bingo It's Compelted!";

Codeigniter Facebook app POST method AND query_string

I have a toy facebook app I'm playing with so I can understand how it all works. It's fine if you go the the app like this: http://apps.facebook.com/pushup-challenge/ (and connect it). But if you then go to it from your facebook page, FB uses the URL http://apps.facebook.com/pushup-challenge/?ref=bookmarks.
In my log file, I see that FB is POSTing the data and including the /?ref=bookmarks to it's call to my codeigniter system. This is causing it to either say "invalid URI parameters" or give me a 404, depending on if I've edited the system/core/URI.php file to add rawurlencode() to a particular call.
I've tried using mod_rewrite to get rid of the query_string, too, but since it's POSTing, it doesn't appear to be working (though I'm not exactly sure why).
Has anyone else run into this? How did you fix it?
Thanks in advance,
Hans
try $config['uri_protocol'] = “PATH_INFO”; and set enable_query_strings = TRUE
or
set
$config['permitted_uri_chars'] = 'a-z 0-9~%.:_\-?=';
in config.php
Because it isn't calling your file by name (just ?ref=bookmarks) the server runs thru the standard default files: index.htm, index.html, index.asp. Because you need to accept a POST, you need a server that allows POSTs to htm & html if you choose to use those. Index.asp will accept POSTs on most servers, and that works for me.
SOLUTION: Add a file (index.asp), that calls the real app that you named in the App settings.