Twitter ( php ) - how to get a picture of the user and the email this user uses on the social network

Asked

Viewed 120 times

1

I am not able to find in the documentation whether this data can be accessed or not. The documentation (in my opinion) is very superficial in relation to Facebook SDK documentation. I am using Oauth as the documentation orders. The integration (php) has been done and successfully. From now on I thank ! :)

1 answer

1

Twitter does not free access to user’s email, soon you will not be able to get that information from the API from Twitter. Instead, you have to get this information on the registration form.

// a lib necessárias
require_once('TwitterAPIExchange.php');

// define suas configurações de acesso
$settings = array(
    'oauth_access_token' => "SEU_ACCESS_TOKEN",
    'oauth_access_token_secret' => "SEU_ACCESS_TOKEN_SECRET",
    'consumer_key' => "SEU_CONSUMER_KEY",
    'consumer_secret' => "SEU_CONSUMER_SECRET"
);

// escolha a url que você precisa da documentação, essa é a users/show
$url = 'https://api.twitter.com/1.1/users/show.json';

// o método de requisição, de acordo com a documentação é GET e não POST
$requestMethod = 'GET';

// definindo sua string
$getfield = '?screen_name=j7mbo';

// criando o objeto
$twitter = new TwitterAPIExchange($settings);

// faz a requisição e obtem a resposta dentro da variável $json
$json =  $twitter->setGetfield($getfield)
                 ->buildOauth($url, $requestMethod)
                 ->performRequest();

// transforma tudo para um array json
$result = json_decode($json);

// mostrando/acessando a profile_image_url
echo $result->profile_image_url;
  • 1

    Thanks for the clarification Paulo Costa !

  • $getfield = '?screen_name=j7mbo'; is my user’s name ? Another question : I am testing on localhost and giving SSL problem : Fatal error: Uncaught Exception 'Exception' with message 'SSL Certificate problem: Unable to get local Issuer Certificate' in C: xampp htdocs socialplugins signin-twitter\twitter-api-php\TwitterAPIExchange.php:296 Stack trace: 
#0 C:\xampp\htdocs\socialplugins\signin-twitter\twitter-api-php\index.php(31): 
TwitterAPIExchange->performRequest() #1 {main} thrown in 
C:\xampp\htdocs\socialplugins\signin-twitter twitter-api-php Twitterapiexchange.php on line 296.

  • what may be generating this error ?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.