### Access Token Response Example Source: https://openservice.aliexpress.com/doc/doc.htm?spm=a2o9m.11193487.0.0.372eee0cUB2sDo&nodeId=27493&docId=118729#/?docId=1590 This is an example of the JSON response received after successfully exchanging a code for an access token. It includes details like token validity, user information, and request identifiers. ```JSON { "gopErrorCode": "0", "gopRequestId": "2141244f17116066265020000", "gopResponseBody": "{\"refresh_token_valid_time\":1711779426000, \"havana_id\":\"300002118000\", \"expire_time\":1711693026000, \"locale\":\"zh_CN\", \"user_nick\":\"kr10400008150000\", \"access_token\":\"Your-accesstoken\", \"refresh_token\":\"Your-refreshtoken\", \"user_id\":\"Your-UserID\", \"account_platform\":\"buyerApp\", \"refresh_expires_in\":172800, \"expires_in\":86400, \"sp\":\"ae\", \"seller_id\":\"Your-sellerID\", \"account\":\"Your-accont\", \"code\":\"0\", \"request_id\":\"2141244f17116066265020000\"}", "success": true } ``` -------------------------------- ### PHP Implementation for Getting Access Token Source: https://openservice.aliexpress.com/doc/doc.htm?spm=a2o9m.11193487.0.0.372eee0cUB2sDo&nodeId=27493&docId=118729#/?docId=1590 This PHP code demonstrates how to obtain an access token. Note that system-level APIs require a different request URL. Replace placeholders with your application's credentials and the provided code. ```PHP setApiName($action); $request->addApiParameter("code", "your_code"); try { // Execute API request, using GOP protocol $response = $client->execute($request, Protocol::GOP); // Output the JSON string of the request response result echo json_encode($response); // Output the GOP format string of the request response result echo $response->getGopResponseBody(); } catch (Exception $e) { // Catch exception and print stack information echo $e->getMessage(); } ``` -------------------------------- ### Step 3: Get Access Token Source: https://openservice.aliexpress.com/doc/doc.htm?spm=a2o9m.11193487.0.0.372eee0cUB2sDo&nodeId=27493&docId=118729#/?docId=1590 After user authorization, a temporary code is returned to the redirect URI. This code is then exchanged for an access token via a POST request to the open platform backend. ```APIDOC ## POST /auth/token/create ### Description Exchanges a temporary authorization code for an access token and a refresh token. ### Method POST ### Endpoint https://api-sg.aliexpress.com/rest ### Parameters #### Query Parameters - **code** (string) - Required - The temporary code obtained after user authorization. ### Request Example ```json { "code": "your_code" } ``` ### Response #### Success Response (200) - **access_token** (string) - The access token for authenticating API calls. - **refresh_token** (string) - The refresh token to obtain a new access token. - **expires_in** (integer) - The remaining valid time of the access token in seconds. - **refresh_token_valid_time** (integer) - The valid timestamp of the refresh token in milliseconds. - **user_id** (string) - The user's unique identifier. - **havana_id** (string) - The user's Havana ID. - **user_nick** (string) - The user's nickname. - **locale** (string) - The user's locale setting. - **account_platform** (string) - The platform of the user's account. - **seller_id** (string) - The user's seller ID. - **gopErrorCode** (string) - Error code, '0' indicates success. - **gopRequestId** (string) - Unique identifier for the request. - **success** (boolean) - Indicates if the API call was successful. #### Response Example ```json { "gopErrorCode": "0", "gopRequestId": "2141244f17116066265020000", "gopResponseBody": "{\"refresh_token_valid_time\":1711779426000,\"havana_id\":\"300002118000\",\"expire_time\":1711693026000,\"locale\":\"zh_CN\",\"user_nick\":\"kr10400008150000\",\"access_token\":\"Your-accesstoken\",\"refresh_token\":\"Your-refreshtoken\",\"user_id\":\"Your-UserID\",\"account_platform\":\"buyerApp\",\"refresh_expires_in\":172800,\"expires_in\":86400,\"sp\":\"ae\",\"seller_id\":\"Your-sellerID\",\"account\":\"Your-accont\",\"code\":\"0\",\"request_id\":\"2141244f17116066265020000\"}", "success": true } ``` ``` -------------------------------- ### Java Implementation for Getting Access Token Source: https://openservice.aliexpress.com/doc/doc.htm?spm=a2o9m.11193487.0.0.372eee0cUB2sDo&nodeId=27493&docId=118729#/?docId=1590 Use this Java code to exchange a temporary code for an access token. Ensure you have the IopClientImpl class available and replace placeholders with your actual appkey, appSecret, and the received code. ```Java public static void main(String[] args) { // Appkey of the application. String url = "https://api-sg.aliexpress.com"; String appkey = "your_appkey"; // AppSecret of the application. String appSecret = "your_appSecret"; // Requested API interface name. String action = "/auth/token/create"; // Create an IopClient object and pass in the API address, appkey and appSecret IopClient client = new IopClientImpl(url, appkey, appSecret); // Create an IopRequest object and pass in the API interface name and parameters IopRequest request = new IopRequest(); request.setApiName(action); request.addApiParameter("code", "your_code"); try { // Perform API requests, using the GOP protocol IopResponse response = client.execute(request, Protocol.GOP); // Output the JSON string of the request response result System.out.println(JSON.toJSON(response)); // Output the GOP format string of the request response result System.out.println(response.getGopResponseBody()); } catch (Exception e) { // Catch exception and print stack information e.printStackTrace(); } } ``` -------------------------------- ### Construct Authorization URL - Plain Source: https://openservice.aliexpress.com/doc/doc.htm?spm=a2o9m.11193487.0.0.372eee0cUB2sDo&nodeId=27493&docId=118729#/?docId=1590 Use this URL to initiate the user authorization process. Replace `${callback-url}` and `${appkey}` with your application's specific callback URL and client ID (appkey). ```Plain https://api-sg.aliexpress.com/oauth/authorize?response_type=code&force_auth=true&redirect_uri=${callback-url}&client_id=${appkey} ``` -------------------------------- ### Refresh Access Token in PHP Source: https://openservice.aliexpress.com/doc/doc.htm?spm=a2o9m.11193487.0.0.372eee0cUB2sDo&nodeId=27493&docId=118729#/?docId=1590 This PHP code snippet demonstrates how to refresh an access token using the /auth/token/refresh endpoint. The refresh token should be obtained from a prior token creation response. ```PHP addApiParam('refresh_token', 'Your-refreshtoken');//Please obtain Your-refreshtoken from the create/token response. var_dump($c->execute($request)); ``` -------------------------------- ### Token Refresh Method Source: https://openservice.aliexpress.com/doc/doc.htm?spm=a2o9m.11193487.0.0.372eee0cUB2sDo&nodeId=27493&docId=118729#/?docId=1590 This method allows you to refresh your access token using a valid refresh token. It is recommended to call this method 30 minutes before the current access token expires. The response provides new access and refresh tokens, along with their validity periods. ```APIDOC ## POST /auth/token/refresh ### Description Refreshes the access token using a provided refresh token. This is necessary to obtain a new access token when the current one is about to expire, without requiring the user to re-authorize. ### Method POST ### Endpoint /auth/token/refresh ### Parameters #### Request Body - **refresh_token** (string) - Required - The refresh token obtained from a previous token generation. ### Request Example ```json { "refresh_token": "Your-Refresh_token" } ``` ### Response #### Success Response (200) - **refresh_token_valid_time** (long) - The valid timestamp of the refresh token, in milliseconds. - **havana_id** (string) - The user's Havana ID. - **expire_time** (long) - The expiration timestamp of the access token, in milliseconds. - **locale** (string) - The user's language setting. - **user_nick** (string) - The user's nickname. - **access_token** (string) - The access token used for API call authentication. - **refresh_token** (string) - The refresh token used to obtain a new access token. - **user_id** (string) - The user's ID. - **account_platform** (string) - Indicates the user's account platform. - **refresh_expires_in** (long) - The remaining valid time of the refresh token, in seconds. - **expires_in** (long) - The remaining valid time of the access token, in seconds. - **seller_id** (string) - The seller's ID. - **account** (string) - The user's account email ID. - **code** (string) - The status code of the API call, "0" indicates success. - **request_id** (string) - The unique identifier for the API request. #### Response Example ```json { "refresh_token_valid_time": 1716784148000, "havana_id": "3000021188814", "expire_time": 1714192160000, "locale": "zh_CN", "user_nick": "kr10404958150000", "access_token": "", "refresh_token": " ", "user_id": "2637908814", "account_platform": "buyerApp", "refresh_expires_in": 5183988, "expires_in": 2592000, "sp": "ae", "seller_id": "2637908814", "account": "ae_test_u0000@163.com", "code": "0", "request_id": "212a69f317116001605067741" } ``` ``` -------------------------------- ### Refresh Access Token in Java Source: https://openservice.aliexpress.com/doc/doc.htm?spm=a2o9m.11193487.0.0.372eee0cUB2sDo&nodeId=27493&docId=118729#/?docId=1590 Use this Java code to refresh an access token by calling the /auth/token/refresh API. Ensure you have obtained the refresh token from a previous authorization. ```Java public class MainClass { public static void main(String[] args) { // Initialize the client with the API URL, app key, and app secret String url = "https://api-sg.aliexpress.com"; String appkey = "your_appkey"; String appSecret = "your_appSecret"; IopClient client = new IopClient(url, appkey, appSecret); // Create a new request and set the API name and parameters IopRequest request = new IopRequest(); request.setApiName("/auth/token/refresh"); request.addApiParameter("refresh_token", "Your-Refresh_token"); try { // Execute the request using the GOP protocol IopResponse response = client.execute(request, Protocol.GOP); // Print the response body System.out.println(response.getBody()); } catch (Exception e) { // Handle any exceptions that may occur during the request execution e.printStackTrace(); } } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.