· 7 years ago · Jun 12, 2018, 08:20 PM
1<?php
2
3include_once "library/OAuthStore.php";
4include_once "library/OAuthRequester.php";
5
6$key = 'IntegriaConsumerTestKey'; // this is your consumer key
7$secret = 'IntegriaConsumerTestSecret'; // this is your secret key
8
9$options = array('server' => 'localhost', 'username' => 'root',
10 'password' => 'root', 'database' => 'hgb-db');
11$store = OAuthStore::instance('MySQL', $options);
12
13try
14{
15 // Get the id of the current user (must be an int)
16 $user_id = 1;
17
18 $consumer_key = 'IntegriaConsumerTestKey';
19
20 // Obtain a request token from the server
21 $token = OAuthRequester::requestRequestToken($consumer_key, $user_id);
22
23 // sends email and password
24 $ch = curl_init($token['authorize_uri']);
25 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
26 curl_setopt($ch, CURLOPT_POST, 1);
27 curl_setopt($ch, CURLOPT_HEADER, 0);
28
29 // Sends oauth_token returned by the server in our previous requestRequestToken() call
30 // in our body along with email and passwordlibrary/OAuthStore.php
31 curl_setopt($ch, CURLOPT_POSTFIELDS, array(
32 'oauth_token' => rawurlencode($token['token']),
33 'username' => 'siemike',
34 'password' => 'password', // test password
35 ));
36
37 // authorize
38 $a = curl_exec($ch);
39
40 echo "<pre>" . print_r($a,1) . "</pre>";
41
42 // Request parameters are oauth_token, consumer_key and usr_id.
43 $oauth_token = $token['token'];
44
45 try
46 {
47 $a = OAuthRequester::requestAccessToken($consumer_key, $oauth_token, 15);
48 var_dump($a);
49 }
50 catch (OAuthException $e)
51 {
52 // Something wrong with the oauth_token.
53 // Could be:
54 // 1. Was already ok
55 // 2. We were not authorized
56 }
57}
58catch(OAuthException2 $e)
59{
60 var_dump($e->getMessage());
61}
62
63?>