I'm trying to make a guide on how to integrate Facebook SDK v5 with Laravel 5.0. Have anyone done this before?
First of all i added "facebook/php-sdk-v4" : "~5.0" in composer.json see documentatione here: https://developers.facebook.com/docs/php/gettingstarted
{
"require" : {
"facebook/php-sdk-v4" : "~5.0"
}
}
Next step composer install in CMD
composer install
Next i added a route:
Route::get('/test', 'Facebookintegration@test');
Next i returned a view:
public function test() {
return view('testpage');
}
Next i try to run the info in the view testpage
<?php
require_once URL::asset('vendor/autoload.php');
$fb = new Facebook\Facebook([
'app_id' => 'YOUR_APP_ID',
'app_secret' => 'YOUR_APP_SECRET',
'default_graph_version' => 'v2.5',
]);
?>
Here is where the problems start and this is my current error
main(): Failed opening required 'http://localhost/fbintegration/vendor/autoload.php' (include_path='.;C:\php\pear')
anyone know how to correctly link yo the files?
https://github.com/SammyK/LaravelFacebookSdk
Use this package for Laravel instead.
The code below is to post to facebook after retrieving token from my DB
Route
Route::post('schedulePost', 'HomeController@ exampelSchedulePost');
Composer.json
"require": {
"sammyk/laravel-facebook-sdk": "^3.0"
}
Provider and aliases , refer to Docs
'providers' => [
SammyK\LaravelFacebookSdk\LaravelFacebookSdkServiceProvider::class,
];
'aliases' => [
'Facebook' => SammyK\LaravelFacebookSdk\FacebookFacade::class,
];
public function exampelSchedulePost(Request $request)
{
$postPermission = 0;
$profileToken = DB::table('profiles')->where('user_id',Auth::user()->id)->first();
$fb = App::make('SammyK\LaravelFacebookSdk\LaravelFacebookSdk');
if($profileToken){
try {
$response = $fb->get('/'.$profileToken->uid.'/permissions', $profileToken->access_token);
$permissions = $response->getGraphEdge();
foreach ($permissions as $item) {
if($item['permission'] == 'publish_actions'){
if($item['status']== 'declined'){
$login_link = $fb->getLoginUrl(['email,publish_actions'], 'http://www.URL.com/facebook/callback');
return redirect($login_link);
//Get Permission again
}
}
}
} catch(\Facebook\Exceptions\FacebookSDKException $e) {
dd($e->getMessage());
}
}else{
$login_link = $fb->getLoginUrl(['email,publish_actions'], 'http://www.URL.com/facebook/callback');
return redirect($login_link);
}