Twitter API asatymic/twitter with Laravel 8 - php

I followed his readme and I have done composer dump-autoload a million times, but still I receive an error. Don't know what i am making wrong. I am trying to use v2 version of twitter api. Please help me anyone.
In config/app.php:
'providers' => [
...
Atymic\Twitter\ServiceProvider\LaravelServiceProvider::class,
],
'aliases' => [
...
'Twitter' => Atymic\Twitter\Facade\Twitter::class,
],
In my controller:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Twitter;
class HomeController extends Controller {
public function index() {
$tweets = Twitter::getUserTimeline([
'screen_name' => 'xxxxxxx',
'count' => 10,
'format' => 'json'
]);
dd($tweets);
return view('home');
}
public function about() {
return view('about');
}
}
But I am getting this error:
Error
Call to undefined method Atymic\Twitter\Service\Accessor::getUserTimeline()

Look like you have to import facade
Instead of this
use Twitter;
Import this
use Atymic\Twitter\Facade\Twitter;
If you are using alias then run following command
php artisan config:clear
composer dump-autoload
php artisan optimize

Please look to the twitter api version which you have defined in the .env. you may need to use 1.1 and you are using v2

I think getUserTimeLine is available for version 1.1, and I think as the readme says you can use userTweets for v2

Related

RuntimeException - Session store not set on request - Laravel Socialite - Facebook

I'm using Laravel 5.7 and Laravel/Socialite 3.1.
I want to login using a Facebook app I just configured for this project.
These are the main files I have configured for this:
/.env
...
FACEBOOK_CLIENT_ID=***
FACEBOOK_CLIENT_SECRET=***
FACEBOOK_CALLBACK_URL=http://localhost:8000/auth/facebook/callback
/config/services.php
<?php
return [
...
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect' => env('FACEBOOK_CALLBACK_URL'),
],
];
/routes/api.php
<?php
use Illuminate\Http\Request;
...
Route::get('auth/facebook', 'SocialiteController#redirectToProviderFacebook');
Route::get('auth/facebook/callback', 'SocialiteController#handleProviderCallbackFacebook');
/app/Http/Controllers/SocialiteController.php
<?php
namespace App\Http\Controllers;
use Socialite;
class SocialiteController extends Controller
{
public function redirectToProviderFacebook()
{
return Socialite::driver('facebook')->redirect();
}
public function handleProviderCallbackFacebook()
{
$user = Socialite::driver('facebook')->user();
print_r($user->token);
}
}
My problem is that for some reason I get the error:
RuntimeException
Session store not set on request.
as you can see on the following image:
I don't want to use sessions on this project at all. I just want to get the token from Facebook on the callback inside: function handleProviderCallbackFacebook().
Any idea on how to solve this issue?
Thanks!
From the Socialite documentation
The stateless method may be used to disable session state verification. This is useful when adding social authentication to an API:
return Socialite::driver('google')->stateless()->user();

Laravel passport can't find ApproveAuthorizationController

I'm trying to setup a laravel application with oauth autorization by using the laravel passport functionality. I'm using the official tutorial (https://laravel.com/docs/master/passport). But now if I make a post request to '/oauth/authorize' the following error message occurs:
Class App\Http\Controllers\Laravel\Passport\Http\Controllers\ApproveAuthorizationController does not exist
I don't know what I've been doing wrong. I use the routes getting from 'Passport:routes' and no self defined routes.
I've already made a composer update, install and clear cache but nothing worked.
The problem get caused here:
/**
* Register the routes needed for authorization.
*
* #return void
*/
public function forAuthorization()
{
$this->router->group(['middleware' => ['web', 'auth']], function ($router) {
$router->get('/authorize', [
'uses' => 'AuthorizationController#authorize',
]);
$router->post('/authorize', [
'uses' => 'ApproveAuthorizationController#approve',
]);
$router->delete('/authorize', [
'uses' => 'DenyAuthorizationController#deny',
]);
});
}
I've already tried it by importing the missing class with a use statement but it still wont work.
Can somebody help me?
It looks like you're missing a use statement at the top of a controller or service proivder. Somewhere you have a class being used with out properly importing it first. That's why you're seeing the concatenated string like:
App\Http\Controllers\Laravel\Passport\Http\Controllers\ApproveAuthorizationController.
I assume what you need is this:
use Passport\Http\Controllers\ApproveAuthorizationController;
or Passport in Passport::routes is not being imported, one of the two. In AppServiceProvider:
use Laravel\Passport\Passport;

Class 'Inline\PDF\PDF' not found in laravel using wemersonjanuario/laravelpdf package

I am trying to use this package -> http://packalyst.com/packages/package/wemersonjanuario/laravelpdf
I have installed and configured as per the website and also I had used this package couple of times which worked following the same procedure.
But now its giving the error Class 'Inline\PDF\PDF' not found
Not sure whats the mistake.
Can someone please help me sort this issue.
Below is the sample code
Composer.json file
"h4cc/wkhtmltopdf-i386": "0.12.3",
"wemersonjanuario/laravelpdf": "1.0.*"
app.php file
'providers' => [
// other providers
Inline\LaravelPDF\PDFServiceProvider::class
],
'aliases' => [
// other aliases
'PDF' => Inline\LaravelPDF\PDFFacade::class,
],
In config/laravelpdf.php file
<?php
return [
'executable' => base_path().'/vendor/h4cc/wkhtmltopdf-i386/bin/wkhtmltopdf-i386'
];
PHP Pdf code
use Inline\LaravelPDF\PDFFacade as PDF;
class SummaryHelper
{
public function getReport($date)
{
// Some code
$data = [ ]; // some data in it
$pdf_obj = PDF::loadView('vendor/daily-report', $data);
}
}
Github issue link
I've installed the package and got the same error. The thing is it's just a fork from another package and the guy didn't updated readme.md for correct namespaces. What you need to do it to change Inline to Novanti in config/app.php. Both for service provider and facade.
Then add this to the class where you want to use PDF facade:
use PDF;
Or just use full namespace:
$pdf_obj = \PDF::loadView('vendor/daily-report', $data);
Sorry for this.
I have changed the namespace to Novanti instead of Inline.
Please switch to 1.1.* version and change alias and provider namespaces to Novanti.
I have also updated the README.md to better document this.
Let me know if this works.
Thank you for reporting.

Class 'Paypal' not found in laravel

<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Paypal;
use Redirect;
use Illuminate\Http\Request;
class SubscriptionController extends Controller
{
private $_apiContext;
public function __construct() {
$this->_apiContext = PayPal::ApiContext(
config('services.paypal.client_id'),
config('services.paypal.secret'));
$this->_apiContext->setConfig(array(
'mode' => 'sandbox',
'service.EndPoint' => 'https://api.sandbox.paypal.com',
'http.ConnectionTimeOut' => 30,
'log.LogEnabled' => true,
'log.FileName' => storage_path('logs/paypal.log'),
'log.LogLevel' => 'FINE'
));
}
I'm getting an error that
Class 'Paypal' not found
in SubscriptionController.php line 17
But my IDE shows that it's there, I even used it in another project and its working fine.
In my app.php I have:
'Paypal' => 'Netshell\Paypal\Facades\Paypal',
So it should be good.
Why do I get that error?
Run this command in your Laravel project root to install Paypal composer require netshell/paypal dev-master
After that, add the service provider to app/config/app.php in the providers array.
'providers' => [
// ...
'Netshell\Paypal\PaypalServiceProvider',
]
At the end, add an alias to app/config/app.php in the aliases array
'aliases' => [
// ...
'Paypal' => 'Netshell\Paypal\Facades\Paypal',
]
After that you should be able to use Paypal
Hope it helps
Try getting rid of the use Paypal; line. If you are defining an alias in app.php, I don't think you need a use statement for it - that has been my experience when defining my own aliases.
You can also try defining your alias with a different syntax to see if it helps:
'Paypal' => Netshell\Paypal\Facades\Paypal::class
(notice there are no quotes on the value as it is a reference to a class).
php artisan config:cache fixed it.
Have you tried doing use \Paypal;?

Unable to use Laravel / Socialite with Lumen

I try to use the package Laravel\Socialite in my system in Lumen (5.1)
I added this in the config\services.php file :
<?php
//Socialite
'facebook' => [
'client_id' => '##################',
'client_secret' => '##################',
'redirect' => 'http://local.dev/admin/facebook/callback',
],
In bootstrap\app.php file :
class_alias(Laravel\Socialite\Facades\Socialite::class, 'Socialite');
$app->register(Laravel\Socialite\SocialiteServiceProvider::class);
Then I created a controller for the facebook authentication :
<?php
namespace App\Http\Controllers\Facebook;
use App\Http\Controllers\Controller;
use Laravel\Socialite\Contracts\Factory as Socialite;
class FacebookController extends Controller
{
public function redirectToProviderAdmin()
{
return Socialite::driver('facebook')->scopes(['manage_pages', 'publish_actions'])->redirect();
}
public function handleProviderCallbackAdmin()
{
$user = Socialite::driver('facebook')->user();
}
}
And in the routes.php :
$app->get('/admin/facebook/login', 'App\Http\Controllers\Facebook\FacebookController#redirectToProviderAdmin');
$app->get('/admin/facebook/callback', 'App\Http\Controllers\Facebook\FacebookController#handleProviderCallbackAdmin');
I just followed the documentation, changing according to my needs. When I go to page http://local.dev/admin/facebook/login, I get the following error :
Non-static method Laravel\Socialite\Contracts\Factory::driver() cannot be called statically, assuming $this from incompatible context
Indeed, according to the code, driver function must be instanciate.
EDIT : And if I try to instanciate this class, I get the following error :
Cannot instantiate interface Laravel\Socialite\Contracts\Factory
How do you make this module to work?
here's how that works in my case
in services.php file
'facebook' => [
'client_id' => '***************',
'client_secret' => '***************',
'redirect' => ""
],
i left redirect empty cause my site is multilingual (so, it fills in a bit later with sessions). if you use only one language, put there your callback absolute path. for example
"http://example.com:8000/my-callback/";
also check your config/app.php. in providers array
Laravel\Socialite\SocialiteServiceProvider::class,
in aliases array
'Socialite' => Laravel\Socialite\Facades\Socialite::class,
my routes look like this
Route::get('facebook', 'Auth\AuthController#redirectToProvider');
Route::get('callback', 'Auth\AuthController#handleProviderCallback');
here's auth controllers methods. put in top
use Socialite;
//იობანი როტ
public function redirectToProvider(Request $request)
{
return Socialite::with('facebook')->redirect();
}
public function handleProviderCallback(Request $request)
{
//here you hadle input user data
$user = Socialite::with('facebook')->user();
}
my facebook app
giga.com:8000 is my localhost (so its the same localhost:8000)
as you can see in Valid OAuth redirect URI, you should put there your callback. in my case i use three urls cause i have three languages. in your case it should be just
http://your-domain-name.com:8000/callback
if you work on localhost, you should name your domain in config/services.php
mine look like this
'domain' => "your-domain.com",
after everything run these commands
php artisan cache:clear
php artisan view:clear
composer dump-autoload
restart your server, clear your browser cookies. hope it helps

Categories