我正在创建向Facebook分享帖子的功能,我正在关注文档:https://developers.facebook.com/docs/php/howto/postwithgraphapi。但它不起作用。 这是我的功能
public function shareFB(Request $request, $slugify)
{
$petition = Petitions::where('slug', $slugify)->first();
$access_token = auth()->user()->social_account->access_token;
$fb = new Facebook\Facebook([
'app_id' => config("services.facebook.client_id"),
'app_secret' => config("services.facebook.client_secret"),
'default_graph_version' => 'v2.2',
]);
$linkData = [
'link' => route('petitions.index',$petition->slug),
'message' => $request->get('shareFB'),
];
try {
$response = $fb->post('/me/feed','post', $linkData, $access_token);
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
$share = $response->getGraphNode();
}
这是我在laravel的路线
Route::post('share/p/{slugify}','Frontend\SocialController@shareFB')->name('social.shareFB');
当我点击一个按钮上面有href时,它会显示MethodNotAllowedHttpException。有人帮我解决了!