-
Notifications
You must be signed in to change notification settings - Fork 0
/
getOAuthAndCreatePRIL.php
81 lines (51 loc) · 1.88 KB
/
getOAuthAndCreatePRIL.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
$keySecret = base64_encode('<<API-KEY>>:<<SECRET>>');
$path = "https://api.trustpilot.com/v1/oauth/oauth-business-users-for-applications/accesstoken";
$dataSend = "grant_type=password&username=<<EMAIL>>&password=<<PASSWORD>>"; //PAYLOAD
$qrystr=$path;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $qrystr,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => $dataSend,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_USERAGENT => 'cURL Request to REST server',
CURLOPT_HTTPHEADER => array(
'Authorization: '.$keySecret,
'Content-Type: application/x-www-form-urlencoded'
)
));
$resp = curl_exec($curl);
print curl_error($curl);
$httpReturnCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($httpReturnCode != 200){
echo "HTTP Error: ".$httpReturnCode;
}
$result = json_decode($resp);
$access_token = $result->access_token;
echo $access_token;
//************************************* FURTHER REQUEST *********
$path = "https://api.trustpilot.com/v1/private/product-reviews/business-units/<<BIZUNIT-ID>>/invitation-links";
$dataSend = ""; // CONSTRUCT THE PAYLOAD HERE AS PER DOCUMENTATION
//REFER: https://developers.trustpilot.com/product-reviews-api#Create product review invitation link
$qrystr=$path;
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_URL => $qrystr,
CURLOPT_POSTFIELDS => $dataSend,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_USERAGENT => '',
));
$resp = curl_exec($curl);print_r($resp);
print curl_error($curl);
$httpReturnCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if($httpReturnCode != 200){
echo "HTTP Error: ".$httpReturnCode;
}
//$result = json_decode($resp);
print_r($resp);
?>