· 9 years ago · Nov 15, 2016, 08:44 AM
1$callbackUrl = "http://127.0.0.1/tt.php";
2//https://httpbin.org/get?oauth_admin.php
3//api/rest/products
4$temporaryCredentialsRequestUrl = "http://demo.mandegar.shop/oauth/initiate?oauth_callback=" . urlencode($callbackUrl);
5$adminAuthorizationUrl = 'http://demo.mandegar.shop/mandegarpanel/oauth_authorize';
6$accessTokenRequestUrl = 'http://demo.mandegar.shop/oauth/token';
7$apiUrl = 'http://demo.mandegar.shop/api/rest';
8$consumerKey = '*****';
9$consumerSecret = '**';
10 session_start();
11// session_destroy();
12
13if (!isset($_GET['oauth_token']) && isset($_SESSION['state']) && $_SESSION['state'] == 1) {
14 $_SESSION['state'] = 0;
15}
16try {
17 $authType = ($_SESSION['state'] == 2) ? OAUTH_AUTH_TYPE_AUTHORIZATION : OAUTH_AUTH_TYPE_URI;
18 $oauthClient = new OAuth($consumerKey, $consumerSecret, OAUTH_SIG_METHOD_HMACSHA1, $authType);
19 $oauthClient->enableDebug();
20
21 if (!isset($_GET['oauth_token']) && !$_SESSION['state']) {
22 $requestToken = $oauthClient->getRequestToken($temporaryCredentialsRequestUrl);
23 $_SESSION['secret'] = $requestToken['oauth_token_secret'];
24 $_SESSION['state'] = 1;
25 header('Location: ' . $adminAuthorizationUrl . '?oauth_token=' . $requestToken['oauth_token']);
26 exit;
27 } else if ($_SESSION['state'] == 1) {
28 $oauthClient->setToken($_GET['oauth_token'], $_SESSION['secret']);
29 $accessToken = $oauthClient->getAccessToken($accessTokenRequestUrl);
30 $_SESSION['state'] = 2;
31 $_SESSION['token'] = $accessToken['oauth_token'];
32 $_SESSION['secret'] = $accessToken['oauth_token_secret'];
33 header('Location: ' . $callbackUrl);
34 exit;
35 } else {
36 $oauthClient->setToken($_SESSION['token'], $_SESSION['secret']);
37
38 $resourceUrl = "$apiUrl/products";
39// $oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/json'));
40$oauthClient->fetch($resourceUrl, array(), 'GET', array('Content-Type' => 'application/xml', 'Accept' => '*/*'));
41
42
43print_r($productsList);
44 }
45} catch (OAuthException $e) {
46 echo 'errrrrrrr';
47
48 print_r($e->getMessage());
49 echo "<br>";
50 print_r($e->lastResponse);
51
52 var_dump($_SESSION);
53}