我知道有很多类似的问题,但没有为我工作。我在我的网站上集成了Oauth twitter系统。我可以获取用户的ID,screen_name等。但是,我不知道如何以原始大小或完整尺寸获取用户的个人资料照片。如果您要回答这个问题,请不要复制并粘贴一堆来自Twitter的文档库,因为这对我来说是普通话,而且我已经尝试过它没有成功。我只需要一个url,我可以将用户的id替换为url的一部分,然后将该url作为img的src以html显示(显然,我通过执行来执行此操作)在oAuth php文件中回复"请事先谢谢。
我的代码:
<?php
if(!isset($_SESSION)){
session_start();
}
require 'autoload.php';
use Abraham\TwitterOAuth\TwitterOAuth;
define('CONSUMER_KEY', 'xxxxxxxxxxxxxxxxxxxxxxxxx'); // add your app consumer key between single quotes
define('CONSUMER_SECRET', 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'); // add your app consumer secret key between single quotes
define('OAUTH_CALLBACK', 'http://www.chapatelo.com.ar/chm/peticiones/callback.php'); // your app callback URL
if (!isset($_SESSION['access_token'])) {
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET);
$request_token = $connection->oauth('oauth/request_token', array('oauth_callback' => OAUTH_CALLBACK));
$_SESSION['oauth_token'] = $request_token['oauth_token'];
$_SESSION['oauth_token_secret'] = $request_token['oauth_token_secret'];
$url = $connection->url('oauth/authorize', array('oauth_token' => $request_token['oauth_token']));
header("Location: " . $url);
} else {
$access_token = $_SESSION['access_token'];
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token['oauth_token'], $access_token['oauth_token_secret']);
$user = $connection->get("account/verify_credentials");
$_SESSION["id"] = $user->id;
$_SESSION["usuario"] = $user->screen_name;
$_SESSION["start"] = time();
$_SESSION["expire"] = $_SESSION["start"] + (3600 * 60);
echo '<img src="https://api.twitter.com/1/users/show.json?screen_name=' . $user->screen_name . '"/>'; //Of course, this echo doesn't show any image...
}
?>