Skip to content

Instantly share code, notes, and snippets.

@DustinHigginbotham
Created September 20, 2013 18:39
Show Gist options
  • Select an option

  • Save DustinHigginbotham/6641929 to your computer and use it in GitHub Desktop.

Select an option

Save DustinHigginbotham/6641929 to your computer and use it in GitHub Desktop.
$app->post('/networks/userinfo', function() use ($app) {
$app = $app->request();
$post = $app->post();
$res = $app->response();
$network = $post['network'];
$user = $post['user'];
if ($network == 'twitter') {
$tmhOAuth = new \tmhOAuth(array(
'token' => "***TWITTER ACCESS TOKEN***",
'secret' => "***TWITTER ACCESS SECRET***",
'consumer_key' => "***TWITTER CONSUMER KEY***",
'consumer_secret' => "***TWITTER CONSUMER SECRET***",
));
$response = $tmhOAuth->user_request(array(
'method' => 'GET',
'url' => $tmhOAuth->url('1.1/users/lookup'),
'params' => array(
'screen_name' => array(
$user
)
),
));
if ($response == 401 || $response == 404) {
$res->status(404);
$res->body('Could not find user');
return;
}
if ($tmhOAuth->response) {
$twitterUser = reset(json_decode($tmhOAuth->response['response']));
if (!$twitterUser || (is_object($twitterUser) && !property_exists($twitterUser, 'id'))) {
$this->response->status(404);
$this->response->body('Could not find user');
return;
}
$user_id = $twitterUser->id;
$user_full_name = $twitterUser->name;
}
} else {
/**
* We also need to check the ID for our Instagram users.
*/
// Basic config based on our stream's info
$config = array(
'client_id' => '****INSTAGRAM ID*****',
'client_secret' => '****SECRET*****',
'grant_type' => 'authorization_code',
'redirect_uri' => 'https://'. $_SERVER['SERVER_NAME'],
"verify_token" => uniqid()
);
// now we are just setting up our Instagram object
$instagram = new \Instagram($config);
$instagram->setAccessToken('***INSTAGRAM ACCESS TOKEN***');
// Search for that user by their sn
// Then grab their ID
$instaUser = $instagram->searchUser($user);
$instaUserObj = json_decode($instaUser);
if (count($instaUserObj->data) === 0) {
$res->status(404);
$res->body('Could not find user');
return;
}
$user_id = (int)$instaUserObj->data[0]->id;
$user_full_name = $instaUserObj->data[0]->full_name;
}
echo json_encode(array('id' => $user_id, 'name' => $user_full_name));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment