我认为造成这种情况的根本原因是我对 Facebook API 工作原理的普遍误解,所以我希望有更多知识的人能指出我正确的方向。
我要做的就是将我们的一个客户的 facebook 画廊返回到两个不同的页面上,这些页面托管在不同的服务器上。我在一页上使用这种格式:
$albums = json_decode( file_get_contents('http://graph.facebook.com/'.$facebook_ID.'/albums') );
这很好用,我得到了我需要的东西。但是,在其他站点上执行此操作会给我此错误:
"message":"An access token is required to request this resource."
如果我所做的只是请求公共画廊,它真的需要访问令牌吗?更让我困惑的是,如果我只是把它放在我的浏览器中:
http://graph.facebook.com/$facebook_ID/albums
我得到了所有必需的信息。这使我倾向于认为这不是域问题?
谢谢!
- - 编辑 - -
这是 curl 的更多信息。
首先 - 有效的请求,来自我的本地盒子:
* 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
然后这是来自我们实时服务器的请求 - EC2 实例(如果这是相关的)
* 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)