質問編集履歴
2
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -64,7 +64,7 @@
|
|
64
64
|
|
65
65
|
|
66
66
|
|
67
|
-
$code = $_GET["code";
|
67
|
+
$code = $_GET["code"];
|
68
68
|
|
69
69
|
$params = array(
|
70
70
|
|
1
行っている流れ、及び挙動
test
CHANGED
File without changes
|
test
CHANGED
@@ -15,3 +15,137 @@
|
|
15
15
|
|
16
16
|
|
17
17
|
よろしくお願いします。。
|
18
|
+
|
19
|
+
|
20
|
+
|
21
|
+
※試した方法というか
|
22
|
+
|
23
|
+
まず
|
24
|
+
|
25
|
+
test.phpで
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
https://api.thebase.in/1/oauth/authorize?response_type=code&client_id=【client_id】&redirect_uri=【コールバックURL】&scope=read_users%20read_orders%20read_items&state=【任意のstate名】
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
上記のURLを叩きます。
|
34
|
+
|
35
|
+
設定したコールバックURLに認可コード付きで返ってくる感じなのですが
|
36
|
+
|
37
|
+
http://【URL】/callback.php ←設定したコールバックURL
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
test.phpのURLを叩くとどうしても
|
42
|
+
|
43
|
+
![![イメージ説明](7b30ee7d1d764952e351fac79019eead.png)](f316ff333d6415b152f68eb931702012.png)
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
この認証画面で止まってしまいます。
|
48
|
+
|
49
|
+
手動で認証ボタンを押さないとコールバックURLにリダイレクトされない感じです。
|
50
|
+
|
51
|
+
手動で認証ボタンを押し、認可コードを取得しAPIでデータを取得することはできています。
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
要はこの認可コードの取得をtest.phpでURLを叩いたときに自動でコールバックURLに返ってくれれば
|
56
|
+
|
57
|
+
問題ないのですが。。
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
認可コード取得後のソース ↓↓
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
$code = $_GET["code";
|
68
|
+
|
69
|
+
$params = array(
|
70
|
+
|
71
|
+
'client_id' => CLIANT_ID,
|
72
|
+
|
73
|
+
'client_secret' => CLIENT_SECRET,
|
74
|
+
|
75
|
+
'code' => $code,
|
76
|
+
|
77
|
+
'grant_type' => 'authorization_code',
|
78
|
+
|
79
|
+
'redirect_uri' => REDIRECT_URL,
|
80
|
+
|
81
|
+
);
|
82
|
+
|
83
|
+
$headers = array(
|
84
|
+
|
85
|
+
'Content-Type: application/x-www-form-urlencoded',
|
86
|
+
|
87
|
+
);
|
88
|
+
|
89
|
+
$request_options = array(
|
90
|
+
|
91
|
+
'http' => array(
|
92
|
+
|
93
|
+
'ignore_errors' => true,
|
94
|
+
|
95
|
+
'method' => 'POST',
|
96
|
+
|
97
|
+
'content' => http_build_query($params),
|
98
|
+
|
99
|
+
'header' => implode("\r\n", $headers),
|
100
|
+
|
101
|
+
),
|
102
|
+
|
103
|
+
);
|
104
|
+
|
105
|
+
$context = stream_context_create($request_options);
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
$response_body = file_get_contents('https://api.thebase.in/1/oauth/token', false, $context);
|
110
|
+
|
111
|
+
$response_array = json_decode($response_body);
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
$token = $response_array->access_token; # YOUR ACCESS TOKEN
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
$headers = array(
|
124
|
+
|
125
|
+
'Authorization: Bearer ' . $token,
|
126
|
+
|
127
|
+
);
|
128
|
+
|
129
|
+
$request_options = array(
|
130
|
+
|
131
|
+
'http' => array(
|
132
|
+
|
133
|
+
'method' => 'GET',
|
134
|
+
|
135
|
+
'header' => implode("\r\n", $headers),
|
136
|
+
|
137
|
+
'ignore_errors' => true,
|
138
|
+
|
139
|
+
),
|
140
|
+
|
141
|
+
);
|
142
|
+
|
143
|
+
$context = stream_context_create($request_options);
|
144
|
+
|
145
|
+
|
146
|
+
|
147
|
+
$response_body = file_get_contents('https://api.thebase.in/1/items?limit=100', false, $context);
|
148
|
+
|
149
|
+
$response_array = json_decode($response_body);
|
150
|
+
|
151
|
+
var_dump($response_array);
|