Skip to content

Commit b89c1fd

Browse files
committed
README Update : generating the permanent access token
1 parent 415e8ff commit b89c1fd

File tree

1 file changed

+57
-4
lines changed

1 file changed

+57
-4
lines changed

README.md

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,35 +18,88 @@ composer require phpclassic/php-shopify
1818
```
1919

2020
### Requirements
21-
PHPShopify uses curl extension for handling http calls to the API. So you need to be have enabled the curl extension.
22-
>However if you prefer to use any other available package library for handling HTTP calls, you can easily do so by modifying 1 line in each of the `get()`, `post()`, `put()`, `delete()` methods in `PHPShopify\ShopifyAPI` class.
21+
PHPShopify uses curl extension for handling http calls. So you need to have the curl extension installed and enabled with PHP.
22+
>However if you prefer to use any other available package library for handling HTTP calls, you can easily do so by modifying 1 line in each of the `get()`, `post()`, `put()`, `delete()` methods in `PHPShopify\HttpRequestJson` class.
2323
2424
## Usage
2525

2626
You can use PHPShopify in a pretty simple object oriented way.
2727

2828
#### Configure ShopifyClient SDK
29-
If you are using your own private API, provide the ApiKey and Password. For Third party apps, use the permanent access token which you have got from the app.
29+
If you are using your own private API, provide the ApiKey and Password.
3030

3131
```php
3232
$config = array(
3333
'ShopUrl' => 'yourshop.myshopify.com',
3434
'ApiKey' => '***YOUR-PRIVATE-API-KEY***',
3535
'Password' => '***YOUR-PRIVATE-API-PASSWORD***',
3636
);
37+
38+
PHPShopify\ShopifyClient::config($config);
3739
```
3840

39-
Or
41+
For Third party apps, use the permanent access token.
4042

4143
```php
4244
$config = array(
4345
'ShopUrl' => 'yourshop.myshopify.com',
4446
'AccessToken' => '***ACCESS-TOKEN-FOR-THIRD-PARTY-APP***',
4547
);
48+
49+
PHPShopify\ShopifyClient::config($config);
50+
```
51+
##### How to get the permanent access token for a shop?
52+
There is a AuthHelper class to help you getting the permanent access token from the shop using oAuth.
53+
54+
1. First, you need to configure the client with additional parameter SharedSecret
55+
56+
```php
57+
$config = array(
58+
'ShopUrl' => 'yourshop.myshopify.com',
59+
'ApiKey' => '***YOUR-PRIVATE-API-KEY***',
60+
'SharedSecret' => '***YOUR-SHARED-SECRET***',
61+
);
62+
63+
PHPShopify\ShopifyClient::config($config);
64+
```
65+
66+
2. Create the authentication request
67+
68+
> The redirect url must be white listed from your app admin as one of **Application Redirect URLs**.
69+
70+
```php
71+
$scopes = 'read_products,write_products,read_script_tags,write_script_tags';
72+
//This is also valid
73+
//$scopes = array('read_products','write_products','read_script_tags', 'write_script_tags');
74+
$redirectUrl = 'https://yourappurl.com/your_redirect_url.php';
75+
76+
\PHPShopify\AuthHelper::createAuthRequest($scopes, $redirectUrl);
77+
```
78+
79+
3. Get the access token when redirected back to the `$redirectUrl`
80+
81+
```php
82+
PHPShopify\ShopifyClient::config($config);
83+
$accessToken = \PHPShopify\AuthHelper::getAccessToken();
84+
//Now store it in database or somewhere else
85+
```
86+
87+
> You can use the same page for creating the request and getting the access token. In that case just skip the 2nd parameter `$redirectUrl` while calling `createAuthRequest()` method. The AuthHelper class will do the rest for you.
88+
89+
```php
90+
PHPShopify\ShopifyClient::config($config);
91+
$accessToken = \PHPShopify\AuthHelper::createAuthRequest($scopes);
92+
//Now store it in database or somewhere else
4693
```
4794

4895
#### Get the ShopifyClient SDK Object
4996

97+
```php
98+
$shopify = new PHPShopify\ShopifyClient;
99+
```
100+
101+
You can provide the configuration as a parameter while instantiating the object (if you didn't configure already by calling `config()` method)
102+
50103
```php
51104
$shopify = new PHPShopify\ShopifyClient($config);
52105
```

0 commit comments

Comments
 (0)