I am using the Facebook PHP SDK to post content to our company page. 9 times out of 10, it works, but on the odd occasion like today the post is submitted and its content appears on the page but without the image provided by the og:image meta tag.
In today's case, a URL was submitted but no image is being displayed. According to Facebook's Sharing Debugger, there is a warning stating the "provided og:image URL encountered an unexpected error", despite the server access logs showing a request made to that image URL by the Facebook crawler at around the time the URL was submitted and a code 200 being returned along with 1MB+ of data.
The Object Debugger says different. It claims the web server is not running or Facebook's crawlers are being blocked, which according to the firewall logs is not the case. There are also warnings stating the og:url and fb:app_id tags are missing even though they appear in the raw output.
Scraping the URL again does not pull the image through; I have to manually use the "refresh share attachment" feature to make the image appear.
Is there any way I can rescape a URL and refresh the share attachment using PHP without having to do it manually?
Scraping the URL again does not pull the image through; I have to manually use the "refresh share attachment" feature to make the image appear.
Of course it doesn’t, otherwise I would change the kitten picture of that article of mine you posted three days ago, to “buy cheap viagra here” today, and you would automatically have that reflected on your timeline …
Is there any way I can rescape a URL and refresh the share attachment using PHP without having to do it manually?
You can (re-)scrape URLs via API – https://developers.facebook.com/docs/sharing/opengraph/using-objects#update
But I am not sure whether updating a post with the exact same values would actually count as an update, and refresh the attachment. You can give it a try (https://developers.facebook.com/docs/graph-api/reference/v3.1/post#updating), but if it doesn’t work, then your only option is to make sure everything is working properly before you make the post. (The JSON data returned from that endpoint should contain the image URL if everything worked properly, I suppose.)
Related
I'm looking for some help in how best to handle page navigation/redirection from a PHP application. We don't offer many downloads so this has only just now come up as an issue. The gist is that a user loads a webpage to view some data and this page offers a hyperlink to download the data into a spreadsheet (dynamically built). The issue that I'm struggling to come up with a slick solution to is if the user sits on the webpage for long enough to where their session expires in PHP. Suppose in that case the user comes back to the page and clicks the download link.
There are two scenarios I need to handle. The first is with old browsers like IE (have to support it for the time being). IE doesn't support the download attribute for ANCHOR elements. Therefore, when the link is clicked and the session is invalid, the user is presented with a login form but the browser URL now reflects the endpoint of the download. Upon logging in, the download functions correctly but the user is left at the login form because the presence of the Content-Type: attachment makes the browser not navigate. I am looking for how to best get the user back to what is essentially the initial HTTP_REFERER when the download was requested. The only idea I can come up with is either a standard endpoint or query string parameter to use so that my login form handling code can properly redirect after successful login for a download request.
The other scenario is for modern browsers that support the download attribute. My code does set the HTTP response code to 401 when it determines the login form needs to be rendered (maybe that's not correct though). I do not see anything within $_SERVER that alludes to that fact though which suggests, again, a standard endpoint or query string parameter to use for identification. Modern browsers handle this case well by simply denying the download and actually displays that the request needs authorization. So, this works well as long as setting the status to 401 on all login form renders is correct otherwise, I'd again need some way to know that the requested endpoint is a download.
I'd like to avoid any kind of JavaScript solution if possible.
I made a one time URL system, that has a token that becomes invalid once the user accesses that URL.
I send the email to the client with the URL containing the token, when he commits a form.
It works fine for people who uses Gmail and whatnot. However, many of the clients who use Hotmail complained that always when they clicked the URL even for the first time, it was already invalid.
I ended up finding out that Outlook has a Link Preview function, enabled by default, that display a little preview of the links in the email. Since this function accesses the URL once, the token becomes invalid when the client opens the email.
Is there a way in PHP to detect if the access to a URL is being done by a link preview system? That way I could make the token invalid only when the access was not made by a link preview.
The outlook preivew request is using HEAD request here. You can check the request type and do not invalidate your link with HEAD request.
(A better solution will be stopping triggering any logic with a simple GET request. You can create a button instead of link to ask users to click. Preview bot is unlikely to click a button like users.)
Using PHP, I'm trying to download file from this link:
http://creator.zoho.com/DownloadFile.do?filepath=/1472044441814_Lighthouse.jpg&sharedBy=29184456.
I've tried everything like copy(), file_put_contents("img.jpeg",file_get_contents($url)), curl but none work.
What's happening is that they create a image file in my server but when I view it, it shows me all the html and css and stuff like this, when I view it on window previewer it says that it can preview the picture etc etc.
Can someone please what I'm doing wrong here. Thank you.
The site probably intentionally tries to make it as hard as possible.
Actually, there are 2 main ways to check this:
Checking the session ids, and allowing the image download only from logged in sessions of users allowed to see that picture,
Checking http referer.
The second is much more common.
Improve your http request to contain a valid, logged in session id and the referer what a real browser would provide. You can do this by checking the cookies and http request parameters of a regular browser. You can do very easily, for example, with the Firebug extension of the Firefox.
I'm way behind with my sleep for the last few days and a client of mine has an end-of-the-world problem after moving a website to a new hosting, which I can't figure out. The issue is quite trivial - retrieving the Facebook photo of users. This worked just fine until now, but apparently some setting on the new server are causing it to fail. The problem is that
file_get_contents('https://graph.facebook.com/me/picture?access_token=VALID_ACCESS_TOKEN&type=large')
returns an empty string. I also tried using another url, which doesn't rely on an access token (although, the access token is valid, because I get other info about the user):
file_get_contents('https://graph.facebook.com/'.$user->id.'/picture?type=large')
where $user->id is the Facebook ID of the user. Manually opening the above URLs in the browser shows the photo, using the same code on my local server also shows them, but on the website the result is always an empty string, no errors, no exceptions.
I checked server settings, openssl is enabled, allow_url_fopen also. Any ideas as to what else can be causing this?
You may be having trouble because /<user>/picture returns a HTTP 301 redirect to the image (i.e you can include it directly in an <img src=""/>)
Try querying /<user>?fields=picture and parsing the URL from that response, rather than trying to directly include it
This is driving me mad. I'm getting a 406 error when I make an AJAX request at my hosting (Linux), but not on my local machine (Windows 7). Both using Apache. All other requests that have the same format, e.g.
http://cms.hogsmill.com/Lib/actionCMS.php?Action=saveContentText&SectionId=155&Text=...
where ... is the text I'm sending - all work fine. The text is Javascript encodeURI'ed before sending. The text that breaks is the following; seems to be something wrong with the "by default all users..." paragraph.
Any ideas?
To create a new page, click on 'New Page'. To edit an existing page click the edit page icon. In both cases, the editor on the left will popup.
Type in the name of the page in the 'Label' field. The URL for the page will be automatically populated. Only edit the URL if it doesn't look sensible. You can only change the URL for a new page; if you need to change an existing URL, contact Hogsmill.
By default, all pages are accessible by everybody. To limit access just to logged in users, unclick 'All' and select a different user type.
Typically there are two types of users:
Site Admin - able to edit content, and see all logged in only pages.
User - cannot edit content, but can see all logged in only pages.
Probably, the best, it's to analyze the HTTP headers of Your client request. It should contain some "Accept" headers, which conflicts with server response, as I understood the nature of this anomaly.
Details for 406 status code
this recently happened to me, using Chrome, headers viewed through Chrome's developer tools seemed to indicate everything was fine, then the next test, it worked without an error. so I have no idea what "fixed" it.