Reputation: 676
I think the root cause of this is my general misunderstanding of how the Facebook API works, so I hope someone with a bit more knowledge can point me in right direction.
All I'm trying to do is return a facebook gallery for one of our clients onto two different pages, hosted on different servers. I use this format on one page:
$albums = json_decode( file_get_contents('http://graph.facebook.com/'.$facebook_ID.'/albums') );
And this works fine, I get what I need. However, doing this on the other site gives me this error:
"message":"An access token is required to request this resource."
Does it really need an access token if all I am doing is requesting a public gallery? To further confuse me, if I simply put this in my browser:
http://graph.facebook.com/$facebook_ID/albums
I get all the required info. This tends me towards thinking it's not a domain issue?
Thanks!
--- EDIT ---
Here's some more info with curl.
First - the request that works, from my local box:
* About to connect() to graph.facebook.com port 80 (#0)
* Trying 69.171.242.27...
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
^M 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0* Connected to graph.facebook.com (69.171.242.27) port 80 (#0)
> GET /370438539411/albums HTTP/1.1
> User-Agent: curl/7.29.0
> Host: graph.facebook.com
> Accept: */*
>
< HTTP/1.1 200 OK
< Access-Control-Allow-Origin: *
< Cache-Control: private, no-cache, no-store, must-revalidate
< Content-Type: application/json; charset=UTF-8
< ETag: "2829e31bfef4b737cdb31aab0f73c8ad35826012"
< Expires: Sat, 01 Jan 2000 00:00:00 GMT
< Pragma: no-cache
< X-FB-Rev: 801567
< X-FB-Debug: /uN6PrzpTWLLaJOn8vuww0ECYjineJN6P9w/DvvVczY=
< Date: Wed, 01 May 2013 12:01:26 GMT
< Connection: keep-alive
< Content-Length: 35483
<
ALL THE THINGS
And then here is the request from our live server - an EC2 instance ( if this is relevant )
* About to connect() to graph.facebook.com port 80 (#0)
* Trying 173.252.101.26... % Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
^M 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0connected
* Connected to graph.facebook.com (173.252.101.26) port 80 (#0)
> GET /370438539411/albums HTTP/1.1
> User-Agent: curl/7.29.0
> Host: graph.facebook.com
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Access-Control-Allow-Origin: *
< Cache-Control: no-store
< Content-Type: application/json; charset=UTF-8
< Expires: Sat, 01 Jan 2000 00:00:00 GMT
< Pragma: no-cache
< WWW-Authenticate: OAuth "Facebook Platform" "invalid_token" "An access token is required to request this resource."
< X-FB-Rev: 801567
< X-FB-Debug: wSxKF5MlCAmEFf2BuYRBDotWWreR6/t5m5mebc8vDXw=
< Date: Wed, 01 May 2013 12:03:38 GMT
< Connection: keep-alive
< Content-Length: 112
<
^M 0 112 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0{ [data not shown]
^M100 112 100 112 0 0 181 0 --:--:-- --:--:-- --:--:-- 212
* Connection #0 to host graph.facebook.com left intact
* Closing connection #0
{"error":{"message":"An access token is required to request this resource.","type":"OAuthException","code":104}}
(END)
Upvotes: 1
Views: 1376
Reputation: 4466
There might be some or the other thing that might make or break access to public data like they way you are accessing. As you have already experienced this, I would like you to go safe on this and instead create an App and use an App Access Token to query for the public data instead of going to it directly as Facebook might in near future even change this..
Upvotes: 1