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
Related
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.)
I am trying to login to a website using postman.
The website is done using PHP and I have the username and the password for it.
I installed burp to check what are we posting in order to login, and it shows the following:
However, when I add the 3 of the parameters with their correct values in POSTMAN the site does not login, and I get the login page again, which means there is something wrong with the info I am sending.
I suspect this is the cookie, but how can I send a cookie with the Header's parameters in POSTMAN?
Although the same cookie appears below in the cookies section in POSTMAN as below.
EDIT 1:
The reason I am posting this is because I want to save to a CSV format the contents of a webpage by creating a PHP script that will go through the pages that are in this format http://example.com/page.php?id=151 and http://example.com/page.php?id=152 and so forth.
However, as mentioned my problem is the authentication where I can't seem to bypass the login page even though I have the username and the password.
At the moment, I am trying this using postman, to see if it is possible, because if it so, I will try to code it in PHP, but It is not working.
I would recommend you the following:
Run the request in your browser, open Dev Tools, copy the request as curl and import it in Postman. See a video on how to do it: https://youtu.be/lqqYBLJR1Yc
It is possible that the form you are submitting includes other values as well, such as a CSRF token, which is generated with each page load. If this is the case, things get more complicated - just let me know how it worked out.
I am trying to use get_meta_tags function to fetch meta info of url. it is failed to give me meta info of url from same origin or domain.
like i am doing it from a controller http://example.com/fetch
$tags=get_meta_tags("http://example.com/blog/my-awesome-blog-post");
print_r($tags);
trying to get metainfo of a page on my site http://example.com/blog/my-awesome-blog-post.
Sharing two screenshots:
Dev instance error:
Local Instance:
Getting error like failed to open stream: Redirection limit reached, aborting. This is the error i am getting.
I tried with different urls (Except facebook). I am getting successful results.
Is there anyway i can achieve this functionality.
I don't know about your localhost but this is what I have deduced from your scenario.
Your website(or the page you are accessing) keep redirecting to a new URL every time PHP tries to access the url. When, the limit of max redirection i.e. 20 is reached PHP stops following and gives you the error.
This is happening because PHP request is a simple http request which is not handling any session/cookies values. So, Your website always treats it as a new request and keeps redirecting.
To verify, Please note that when you open your URL(https://dev.kidengage.com/library) in a incognito window it redirects you to https://dev.kidengage.com/hyderabad to set location for the user. And, after cookies are set, no more redirections takes place for the given URL.
This is where redirections are happening.
So, you need to fix this first or write a custom CURL script to fetch the data which can handle the session as well as redirections.
Hope it would help.
This is something that I in practice so far I have not seen before.
I made a web app which works beautifully on all devices (so far I was thinking). Last week I received a few complaints that one part of the application does not work. Maybe I've reviewed over 100 times my code and I have not found a mistake and error behavior is that at one point the session expires or is just is not setup - which is not possible. The system was tested on a pile of users.
Today I received a response from a client that uses the iPhone 5. And really happens is that sessions are not working properly.
I use this session to force the user to open the pages in the order and that there is no possibility of jumping from page to page. If the user tries to skip the page, just go back to the beginning and need to re-start the process.
On the iPhone during the process returns me to the start and stop. It does not allow you to go to level 1 just returning back until you clear you cache.
This error happen randomly anywhere in process.
-To mention, I sessions not deleted until the user reache the end.
Is it possible that the iPhone has a problem with their browser or is error on my side?
Thanks!
This is what that solved the same problem i was facing earliar. May this will help..
the session problems for login page might occur because the url you are opening in the browser are not unique. for example If say you are creating a login page for your website, and you have created sessions successfully. Now, if you are logging in from url say http://geekzgarage.com then your session is limited to this url only. If you again open the above url like http://www.geekzgarage.com (note www. in both urls), then you will see that you are not logged in. So please be sure that your webpage is opening always in single type of url. either with www. or without www.
After research I found that alot of people facing the same issue. But so far I don't solution, this happened after I switch my server to linode.com
lets take an example. www.acemark2u.com is one of the website hosted under the linode server,
when I try to debug in https://developers.facebook.com/tools/debug/og/object/, it just couldn't fetch the scrape information correctly, and if I try with one of the page www.acemark2u.com/about-us, it just show me the error "Error parsing input URL, no data was cached, or no data was scraped."
weird things happen. when I try to debug using ip address 106.187.35.114/~acemark2 everything goes smooth. fetching nicely, no error 404 for pages.
I suspect it might caused by "gethostbyaddr" function (ref: http://www.gearhack.com/Forums/DisplayComments.php?file=Computer/Network/Internet/Preventing_Your_Web_Server_From_Blocking_Facebook_Share) but so far I don't have solutions.
For people experiencing the same issue but for different causes, I discovered a few interesting things about how Facebook "scrapes" pages, checking the logs of the server while doing some trials.
First of all: if you never tried to share a page with FB, FB never tried to scrape it, and it will not try to do so if you only put the url in the Debug tool.
That's the first reason because you get the error: it just states that FB has no information on the page, you must "force" it to scrape the page.
The first time you try to share a page, FB scrapes it (asks your server the first 40k of the page and analyse the opengraph tags).
What can happen is that you do not see the image: Facebook Share Dialog does not display thumbnails one first load
The reason is that FB behind the scenes is still scraping your page and caching the image. The next time, in fact, you have also the image.
How to solve it? Pre caching: https://developers.facebook.com/docs/sharing/best-practices#precaching
or simply add
<meta property="og:image:width" content="450"/>
<meta property="og:image:height" content="298"/>
i found the solution at last.
In my default DNS A/AAAA record i did not remove these few ip
2400:8900::f03c:91ff:fe73:a95d Default
mail 2400:8900::f03c:91ff:fe73:a95d Default
www 2400:8900::f03c:91ff:fe73:a95d Default
that's why some of the users will pointed to the above IP when they access via proper web address.
This question has already accepted answer but in case this answer doesn't work for anyone here is what worked for me.
The URL which I provided in the og:url was protected URL i.e. only those users can view the page pointed by the URL who are signed-in. When I changed the URL to point to my homepage which can be viewed by both signed-in or signed-out users viz. http://www.ercafe.com everything worked fine.
We had a similar issue on one of our sites.
We resolved this by disabling apache mod_security while we use the facebook object debug tool to "fetch new scrape information"
For me the solution was replacing the DNS A records
example.sk 3600 1.2.3.4
www.example.sk 3600 1.2.3.4
to
example.sk 3600 1.2.3.4
*.example.sk 3600 1.2.3.4