Twitter (php) - how to get the user image and the email that this user uses on the social network

1

I can not find in the documentation whether this data can be accessed or not. The documentation (in my opinion) is very superficial regarding the documentation of the Facebook SDK. I'm using OAuth as the documentation says. Integration (php) has already been done successfully. Thank you in advance! :)

    
asked by anonymous 08.05.2015 / 22:39

1 answer

1

Twitter does not release access to the user's email , so you will not be able to get this information from the API of Twitter. Instead, you have to get this information in the application 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;
    
08.05.2015 / 22:52