Мне просто интересно, почему я продолжаю получать HTTP-код 403 здесь. Я использую библиотеку PHP TwitterAAuth от Авраама.
Я пытаюсь получить доступ к API Twitter и продолжаю получать сообщение об этой ошибке. Я был добавить учетные данные в базу данных из OAuth.php
OAuth.php
<?php
//add autoload note:do check your file paths in autoload.php
require "twitteroauth/autoload.php";
use Abraham\TwitterOAuth\TwitterOAuth;
include_once("User.php");
//this code will run when returned from twiter after authentication
if(isset($_SESSION['oauth_token'])){
$oauth_token=$_SESSION['oauth_token'];unset($_SESSION['oauth_token']);
$consumer_key = 'XXXXXXXXX';
$consumer_secret = 'XXXXXXXXXXXXXXXXXXXXXXXXXXXXX';
$connection = new TwitterOAuth($consumer_key, $consumer_secret);
//necessary to get access token other wise u will not have permision to get user info
$params=array("oauth_verifier" => $_GET['oauth_verifier'],"oauth_token"=>$_GET['oauth_token']);
$access_token = $connection->oauth("oauth/access_token", $params);
//now again create new instance using updated return oauth_token and oauth_token_secret because old one expired if u dont u this u will also get token expired error
$connection = new TwitterOAuth($consumer_key, $consumer_secret,
$access_token['oauth_token'],$access_token['oauth_token_secret']);
$content = $connection->get("account/verify_credentials");
$_SESSION['content']=$content;
var_dump($content);
print_r($content);
}
else{
session_start();
// main startup code
$consumer_key = 'cxRRuxImbjqr5ZGEkc4c5iWfG';
$consumer_secret = 'KvwqPX5XLwZXDwmrYBiVWvQAQZszK1rNxahFOAV3PAZanNDQrH';
//this code will return your valid url which u can use in iframe src to popup or can directly view the page as its happening in this example
$connection = new TwitterOAuth($consumer_key, $consumer_secret);
$temporary_credentials = $connection->oauth('oauth/request_token', array("oauth_callback" =>'http://localhost/Social/HomePage.php'));
$_SESSION['oauth_token']=$temporary_credentials['oauth_token'];
$_SESSION['oauth_token_secret']=$temporary_credentials['oauth_token_secret'];
$url = $connection->url("oauth/authorize", array("oauth_token" => $temporary_credentials['oauth_token']));
$connection->get("account/verify_credentials");
//Call Twitter API
$twClient = new TwitterOAuth($consumer_key, $consumer_secret, $_SESSION['oauth_token'], $_SESSION['oauth_token_secret']);
//$connection = new TwitterOAuth($consumer_key, $consumer_secret,
//$access_token['oauth_token'],$access_token['oauth_token_secret']);
//Get user profile data from twitter
$userInfo = $twClient->get('account/verify_credentials.json');
//$user_infos = $twitter_conn->get("account/verify_credentials");
//Initialize User class
$user = new User();
//Insert user into the database
//Insert or update user data to the database
$name = explode(" ",$userInfo->name);
$fname = isset($name[0])?$name[0]:'';
$lname = isset($name[1])?$name[1]:'';
$profileLink = 'https://twitter.com/'.$userInfo->screen_name;
$twUserData = array(
'oauth_provider'=> 'twitter',
'oauth_uid' => $userInfo->id,
'first_name' => $fname,
'last_name' => $lname,
'email' => '',
'gender' => '',
'locale' => $userInfo->lang,
'picture' => $userInfo->profile_image_url,
'link' => $profileLink,
'username' => $userInfo->username
);
$userData = $user->checkUser($twUserData);
// $user_info = $connection->get('account/verify_credentials');
// $name = explode(" ",$user_info->name);
// $fname = isset($name[0])?$name[0]:'';
// $lname = isset($name[1])?$name[1]:'';
// $db_user = new User();
// $db_user->checkUser($twUserData);
// REDIRECTING TO THE URL
if (200 == $connection->getLastHttpCode()) {
header('Location:' . $url);
} else
{
echo "Hello world!", $connection->getLastHttpCode();
}
}
?>
Задача ещё не решена.
Других решений пока нет …