我有一个Facebook用户通过Laravel 4中的PHP控制器登录(使用Taylor Otwell包),但我不确定如何将我的访问令牌发送到我的javascript SDK调用以共享照片(/ me / photos )。
这是Javascript,点击时调用:
/* make the API call */
function facebookInit() {
FB.api(
"/me/photos",
"POST",
{
"object": {
"url": "https://graph.facebook.com/**********/picture?width=720&height=720"
}
},
function (response) {
console.log(response);
if (response && !response.error) {
window.location = "http://url.com/artists";
}
}
);
}
记录响应时,出现错误:
代码:2500消息:"必须使用活动访问令牌来查询有关当前用户的信息。"类型:" OAuthException" (FB Photo Share)
我有一个用户使用访问令牌登录,但我不确定如何通过此javascript SDK调用获取该读取。以下是登录用户的控制器中的代码:
public function action_session($provider, $id = null) {
//get facebook sdk
$this->facebook = $this->getFacebook($provider);
//get facebook auth
$this->auth = $this->getFacebookAuth();
if($this->auth) {
return $this->auth;
}
//get facebook access token
$this->accessToken = $this->getAccessToken();
//set facebook access token
$this->facebook->accessToken = $this->accessToken;
if(!session_id()) {
session_start();
}
$_SESSION['fb_access_token'] = $this->accessToken;
//get data
$data = array();
//get user
$data['user'] = $this->getUser();
//check if exists (redirect)
$fan = new Fan();
$check = $fan->getFan($data['user']['id']);
if(isset($check->url_tag) && !empty($check->url_tag)) {
$login = Fan::where('fbid', '=', $data['user']['id'])->first();
Auth::login($login);
return Redirect::to('/fans/'.$check->url_tag);
exit;
}
//get picture
$data['picture'] = 'http://graph.facebook.com/'.$data['user']['id'].'/picture?width=720&height=720';
//get friends
$data['friends'] = $this->getFriends();
//get likes
$data['likes'] = $this->getLikes();
//get location
$data['location'] = $this->getLocation();
//assign global data
$this->data = $data;
//check if user exists
if(!$this->userExists($this->data['user']['id'])) {
$this->createFan();
};
//login user
$login = Fan::where('fbid', '=', $data['user']['id'])->first();
Auth::login($login);
return $this->forceRedirect('/fans/welcome');
}
public function getFacebook($provider) {
if($_SERVER['HTTP_HOST'] != 'crowd.com') {
return OAuth2::provider($provider, array('id' => '*************', 'secret' => '*************'));
} else {
return OAuth2::provider($provider, array('id' => '*************', 'secret' => '**************'));
}
}
public function getFacebookAuth() {
if(!isset($_GET['code'])) {
return $this->facebook->authorize();
}
}
public function getAccessToken() {
return $this->facebook->access($_GET['code']);
}
public function getUser() {
return $this->facebook->get('me');
}
我的问题是如何从我的控制器获取登录用户的访问令牌并将其连接到Javascript SDK以便我可以运行此调用?
我知道它正在注册用户登录到Facebook,因为我可以正常使用FB.ui事件(它将识别登录的FB用户)。