· 7 years ago · Jan 10, 2018, 09:54 AM
1$oauth_nonce = md5(uniqid(rand(), true));
2$oauth_timestamp = time();
3
4$oauth_token = $response['oauth_token'];
5$oauth_token_secret = $response['oauth_token_secret'];
6$screen_name = $response['screen_name'];
7
8//create oauth signature
9$params = array(
10 'oauth_consumer_key=' . CONSUMER_KEY . URL_SEPARATOR,
11 'oauth_nonce=' . $oauth_nonce . URL_SEPARATOR,
12 'oauth_signature_method=HMAC-SHA1' . URL_SEPARATOR,
13 'oauth_timestamp=' . $oauth_timestamp . URL_SEPARATOR,
14 'oauth_token=' . $oauth_token . URL_SEPARATOR,
15 'oauth_version=1.0' . URL_SEPARATOR,
16 'screen_name=' . $screen_name,
17 //'include_email=true'
18);
19$oauth_base_text = 'GET' . URL_SEPARATOR . urlencode(ACCOUNT_EMAIL) . URL_SEPARATOR . implode('', array_map('urlencode', $params));
20
21$key = CONSUMER_SECRET . '&' . $oauth_token_secret;
22$signature = base64_encode(hash_hmac("sha1", $oauth_base_text, $key, true));
23
24// get userinfo
25$params = array(
26 'oauth_consumer_key=' . CONSUMER_KEY,
27 'oauth_nonce=' . $oauth_nonce,
28 'oauth_signature=' . urlencode($signature),
29 'oauth_signature_method=HMAC-SHA1',
30 'oauth_timestamp=' . $oauth_timestamp,
31 'oauth_token=' . urlencode($oauth_token),
32 'oauth_version=1.0',
33 'screen_name=' . $screen_name,
34 //'include_email=true'
35);
36
37$url = ACCOUNT_EMAIL . '?' . implode(URL_SEPARATOR, $params);
38$response = file_get_contents($url);
39print_r($response);