回答編集履歴
4
理想
answer
CHANGED
@@ -11,6 +11,7 @@
|
|
11
11
|
public function __construct()
|
12
12
|
{
|
13
13
|
// 共通部分はこういうところでセットしておくとやりやすい
|
14
|
+
// (理想を言うと ServiceProvider からコンストラクタ引数として注入したほうがユニットテストは書きやすかったりするがここでは簡略化)
|
14
15
|
$this->client = new Client([
|
15
16
|
'base_uri' => 'https://api.sansan.com/v2.0/',
|
16
17
|
'headers' => [
|
3
一応書いておく
answer
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
再現することが考えにくい不具合なので,勘違いしている可能性をまず疑ってください。
|
2
2
|
|
3
|
-
|
4
3
|
- 関数内部の `print_r()` で表示と,関数外部の `print_r()` で表示は,どちらも1回のリクエストで一気に表示されたものでしょうか?連続した別々のリクエストで表示されたものではありませんか?
|
5
4
|
|
6
5
|
勘違いしている可能性としては↑が一番濃厚だと思います。
|
@@ -13,9 +12,9 @@
|
|
13
12
|
{
|
14
13
|
// 共通部分はこういうところでセットしておくとやりやすい
|
15
14
|
$this->client = new Client([
|
16
|
-
'base_uri' => 'https://api.
|
15
|
+
'base_uri' => 'https://api.sansan.com/v2.0/',
|
17
16
|
'headers' => [
|
18
|
-
'X-
|
17
|
+
'X-Sansan-Api-Key' => 'xxxxxxxxxxxxxxxxxxx',
|
19
18
|
],
|
20
19
|
]);
|
21
20
|
}
|
@@ -50,7 +49,7 @@
|
|
50
49
|
|
51
50
|
// Guzzle は 200 系以外は Exception をスローするのでステータスコードのチェックは不要
|
52
51
|
// (必要に応じて try-catch 構文で包む必要あり)
|
53
|
-
$response = $this->client->request('GET', '
|
52
|
+
$response = $this->client->request('GET', 'bizCards/search', $options);
|
54
53
|
|
55
54
|
return json_decode($response->getBody(), true);
|
56
55
|
}
|
2
scope
answer
CHANGED
@@ -34,7 +34,7 @@
|
|
34
34
|
return $posts;
|
35
35
|
}
|
36
36
|
|
37
|
-
|
37
|
+
protected function sendRequest($nextPageToken = null)
|
38
38
|
{
|
39
39
|
// クエリストリングは query オプションで連想配列形式で指定できる
|
40
40
|
$options = [
|
1
return 忘れ
answer
CHANGED
@@ -20,19 +20,21 @@
|
|
20
20
|
]);
|
21
21
|
}
|
22
22
|
|
23
|
-
public function
|
23
|
+
public function searchAllData()
|
24
24
|
{
|
25
25
|
// 再帰呼び出しよりはループのほうがいいかも
|
26
26
|
$posts = [];
|
27
27
|
$nextPageToken = null;
|
28
28
|
|
29
29
|
do {
|
30
|
-
$result = $this->
|
30
|
+
$result = $this->sendRequest($nextPageToken);
|
31
31
|
$posts = array_merge($posts, $result['data']);
|
32
32
|
} while ($nextPageToken = $result['nextPageToken']);
|
33
|
+
|
34
|
+
return $posts;
|
33
35
|
}
|
34
36
|
|
35
|
-
public function
|
37
|
+
public function sendRequest($nextPageToken = null)
|
36
38
|
{
|
37
39
|
// クエリストリングは query オプションで連想配列形式で指定できる
|
38
40
|
$options = [
|
@@ -50,6 +52,6 @@
|
|
50
52
|
// (必要に応じて try-catch 構文で包む必要あり)
|
51
53
|
$response = $this->client->request('GET', 'xxxx/search', $options);
|
52
54
|
|
53
|
-
return json_decode($response->getBody(), true)
|
55
|
+
return json_decode($response->getBody(), true);
|
54
56
|
}
|
55
57
|
```
|