我的Laravel应用程序旁边有一个表单
当用户在该表单上提交时,它会发布一个帖子
/facebook/status/post
{!! Form::open(array('url' => '/facebook/status/post', 'class' => 'form-horizontal', 'role' =>'form','id' => 'postFbStatus')) !!}
<input type="text" class="form-control" placeholder="What's your status?">
<button class="btn btn-primary btn-block mt10">Submit Post</button>
{!! Form::close();!!}
路线
Route::post('facebook/status/post','FbController@post');
控制器
public function post(){
$fb = App::make('SammyK\LaravelFacebookSdk\LaravelFacebookSdk');
$id = Auth::user()->account_id;
$token_oauth = DB::table('tokens')->where('account_id','=',$id)->first();
try {
$token = $token_oauth->oauth;
} catch (Facebook\Exceptions\FacebookSDKException $e) {
dd($e->getMessage());
}
//provide the token
$fb->setDefaultAccessToken($token);
// Get basic info on the user from Facebook.
try {
$response = $fb->get('/me?fields=id,name,email');
} catch (Facebook\Exceptions\FacebookSDKException $e) {
dd($e->getMessage());
}
// Convert the response to a `Facebook/GraphNodes/GraphUser` collection
$facebook_user = $response->getGraphUser();
$facebook_id = $facebook_user->id;
$url = 'https://graph.facebook.com/'.$facebook_id.'/feed';
$status = Input::get('status');
$data = [];
$data['access_token'] = $token;
$data['message'] = $status;
$data['from'] = env('FACEBOOK_APP_ID');
$data['to'] = $facebook_id;
$data['caption'] = 'Caption';
$data['name'] = 'Name';
$data['description'] = 'via demo.PHPGang.com';
dd($data);
CURL::POST($url,$data);
}
数据阵列
array:7 [▼
"access_token" => "CAAO8ZBRshTC8BAOIZBlv7ZAZBOtc3y9pggTslVkPzhq1AfD2ihriV2RfAnQVZAQeKuS64rkJvV2YZAE8NrzuCsFpZA6ZB2KEisDYvafd40iflvjhjUFqJ9HpMrDKxSygKoBZAKOkYutVeIxdKsGh3PZAHQHHKv01JFrQl7x7HZBZA1wr3mSm2Dt9RHWkggrdIJ3rumFTPVRZAUKVZCYfgZDZD"
"message" => null
"from" => "105220301f8177583"
"to" => "14239698280f3345"
"caption" => "Caption"
"name" => "Name"
"description" => "via demo.PHPGang.com"
]