Reputation: 149
I already used facebook api by using this.Then i added
'Twitter' => [
'client_id' => '**************',
'client_secret' => '***************',
// No scope - oauth1 doesn't need scope
],
these lines to config/oauth-5-laravel.php
.
then i add the function
public function loginWithTwitter(Request $request)
{
// get data from request
$token = $request->get('oauth_token');
$verify = $request->get('oauth_verifier');
// get twitter service
$tw = \OAuth::consumer('Twitter');
// check if code is valid
// if code is provided get user data and sign in
if ( ! is_null($token) && ! is_null($verify))
{
// This was a callback request from twitter, get the token
$token = $tw->requestAccessToken($token, $verify);
// Send a request with it
$result = json_decode($tw->request('account/verify_credentials.json'), true);
$message = 'Your unique Twitter user id is: ' . $result['id'] . ' and your name is ' . $result['name'];
echo $message. "<br/>";
//Var_dump
//display whole array.
dd($result);
}
// if not ask for permission first
else
{
// get request token
$reqToken = $tw->requestRequestToken();
// get Authorization Uri sending the request token
$url = $tw->getAuthorizationUri(['oauth_token' => $reqToken->getRequestToken()]);
// return to twitter login url
return redirect((string)$url);
}
}
to my controller. but i updated my composer.json. when i connent to twitter..this type of error comes..
TokenResponseException in StreamClient.php line 68: Failed to request resource. HTTP Code: HTTP/1.1 401 Authorization Required
i think there is a problem at the time of app creation.help me
Upvotes: 2
Views: 547