Request a User’s Email Address in Twitter App with PHP -
i working php twitter login system & have requested twitter application on twitter whitelist, can email user when register twitter on website.
my application whitelisted, didn't find tutorial how email in php code.
there code of twitter-login.php page:
<?php require('http.php'); require('oauth_client.php'); require('config.php'); //require('config.php'); $client = new oauth_client_class; $client->debug = 1; $client->debug_http = 1; $client->redirect_uri = redirect_url; //$client->redirect_uri = 'oob'; $client->client_id = client_id; $application_line = __line__; $client->client_secret = secret_key; if (strlen($client->client_id) == 0 || strlen($client->client_secret) == 0) die('please go twitter apps page https://dev.twitter.com/apps/new , ' . 'create application, , in line ' . $application_line . ' set client_id consumer key , client_secret consumer secret. ' . 'the callback url must ' . $client->redirect_uri . ' if want post ' . 'the user timeline, make sure application create has write permissions'); if (($success = $client->initialize())) { if (($success = $client->process())) { if (strlen($client->access_token)) { $success = $client->callapi( 'https://api.twitter.com/1.1/account/verify_credentials.json', 'get', array(), array('failonaccesserror' => true), $user); } } $success = $client->finalize($success); } if ($client->exit) exit; if ($success) { // check if user exist same email id $sql = "select count(*) count users_twitter twitter_id = :id"; try { $stmt = $db->prepare($sql); $stmt->bindvalue(":id", $user->id); $stmt->execute(); $result = $stmt->fetchall(); if ($result[0]["count"] > 0) { // user exist $_session["name"] = $user->name; $_session["id"] = $user->id; $_session["new_user"] = "no"; } else { // new user, insert in database $sql = "insert `users_twitter` (`name`, `twitter_id`) values " . "( :name, :id)"; $stmt = $db->prepare($sql); $stmt->bindvalue(":name", $user->name); $stmt->bindvalue(":id", $user->id); $stmt->execute(); $result = $stmt->rowcount(); if ($result > 0) { $_session["name"] = $user->name; $_session["id"] = $user->id; $_session["new_user"] = "yes"; $_session["e_msg"] = ""; } } } catch (exception $ex) { $_session["e_msg"] = $ex->getmessage(); } $_session["user_id"] = $user->id; } else { $_session["e_msg"] = $client->error; } header("location:home.php"); exit; ?>
i have tried id called: $user->id;
=> $user->email;
, didn't work. have solution this?
email addresses available if application has been whitelisted
Comments
Post a Comment