質問編集履歴
5
情報追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -362,6 +362,6 @@
|
|
362
362
|
|
363
363
|
|
364
364
|
|
365
|
-
|
365
|
+
profile.phpの`$this->topTracks = $api->getMyTop('tracks',['limit' => 3]);`を外した場合は正常に動作します。
|
366
366
|
|
367
367
|
考えられる原因は何でしょうか。ご回答お待ちしております。
|
4
誤字
test
CHANGED
File without changes
|
test
CHANGED
@@ -190,9 +190,9 @@
|
|
190
190
|
|
191
191
|
$session = new SpotifyWebAPI\Session(
|
192
192
|
|
193
|
+
'{client id}',
|
194
|
+
|
193
|
-
'
|
195
|
+
'{client secret}',
|
194
|
-
|
195
|
-
'8a70db5638a64189b7d7b56d4f77da38',
|
196
196
|
|
197
197
|
'http://localhost/php_test/iNTO/iNTO.php'
|
198
198
|
|
3
コードすべてを追加しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,44 +16,348 @@
|
|
16
16
|
|
17
17
|
```php
|
18
18
|
|
19
|
+
<?php
|
20
|
+
|
21
|
+
//パス:C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\iNTO\iNTO.php
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
require_once('../vendor/autoload.php');
|
26
|
+
|
27
|
+
require_once('spotify-web-api-php-master/src/SpotifyWebAPI.php');
|
28
|
+
|
29
|
+
require_once('profile.php');
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
$me = new Profile();
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
$me->setBio('洋楽がすき<br>');
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
?>
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
<html>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<head>
|
50
|
+
|
51
|
+
<title>iNTO</title>
|
52
|
+
|
53
|
+
<link rel="stylesheet" href="iNTO.css" type="text/css">
|
54
|
+
|
55
|
+
</head>
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
<body>
|
60
|
+
|
61
|
+
<div class="upper">
|
62
|
+
|
63
|
+
<h1><a href="http://localhost/php_test/iNTO/iNTO.php">Reload</a></h1>
|
64
|
+
|
65
|
+
<h2>iNTO</h2>
|
66
|
+
|
67
|
+
</div>
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
<div class="wrapper">
|
74
|
+
|
75
|
+
<div class="Pic">
|
76
|
+
|
77
|
+
<?php
|
78
|
+
|
79
|
+
//プロフィール画像取得
|
80
|
+
|
81
|
+
$img = file_get_contents('https://profile-images.scdn.co/images/userprofile/default/43516f5c98c8801ea2ceb67a696d51ce67e9671f');
|
82
|
+
|
83
|
+
$enc_img = base64_encode($img);
|
84
|
+
|
85
|
+
$imginfo = getimagesize('data:application/octet-stream;base64,' . $enc_img);
|
86
|
+
|
87
|
+
echo '<img class="profilePic" src="data:' . $imginfo['mime'] . ';base64,'.$enc_img.'">';
|
88
|
+
|
89
|
+
////
|
90
|
+
|
91
|
+
?>
|
92
|
+
|
93
|
+
</div>
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
<div class="userName">
|
98
|
+
|
99
|
+
<strong><?php echo $me->getUserName() ?></strong>
|
100
|
+
|
101
|
+
</div>
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
<div class="followAndFollower">
|
106
|
+
|
107
|
+
<?php
|
108
|
+
|
109
|
+
echo "フォロワー:" . $me->getFollow()."<br>";
|
110
|
+
|
111
|
+
echo "フォロー:" .$me->getFollow();
|
112
|
+
|
113
|
+
?>
|
114
|
+
|
115
|
+
</div>
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
<div class="bio">
|
120
|
+
|
121
|
+
<?php echo $me->getBio() ?>
|
122
|
+
|
123
|
+
</div>
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
<h3>公開中のプレイリスト</h3>
|
128
|
+
|
129
|
+
<ul>
|
130
|
+
|
131
|
+
<?php foreach($me->getPlaylists()->items as $playlist): ?>
|
132
|
+
|
133
|
+
<li><?php echo $playlist->name ?></li>
|
134
|
+
|
135
|
+
<?php endforeach ?>
|
136
|
+
|
137
|
+
</ul>
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
</div>
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
</body>
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
</html>
|
150
|
+
|
151
|
+
```
|
152
|
+
|
153
|
+
|
154
|
+
|
155
|
+
```PHP
|
156
|
+
|
157
|
+
<?php
|
158
|
+
|
159
|
+
//パス:C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\iNTO\profile.php
|
160
|
+
|
161
|
+
require_once('../vendor/autoload.php');
|
162
|
+
|
163
|
+
|
164
|
+
|
19
165
|
class Profile{
|
20
166
|
|
21
|
-
private $
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
p
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
167
|
+
private $userName;
|
168
|
+
|
169
|
+
private $profilePic;
|
170
|
+
|
171
|
+
private $follower = 0;
|
172
|
+
|
173
|
+
private $follow = 0;
|
174
|
+
|
175
|
+
private $Bio;
|
176
|
+
|
177
|
+
private $playlists;
|
178
|
+
|
179
|
+
private $topTracks;
|
180
|
+
|
181
|
+
private $topArtists;
|
182
|
+
|
183
|
+
|
184
|
+
|
185
|
+
public function __construct(){
|
186
|
+
|
187
|
+
//Spotifyにユーザ認証
|
188
|
+
|
189
|
+
//アクセストークンの取得
|
190
|
+
|
191
|
+
$session = new SpotifyWebAPI\Session(
|
192
|
+
|
193
|
+
'4733439adee7492dbdadb5e0bce5c4ef',
|
194
|
+
|
195
|
+
'8a70db5638a64189b7d7b56d4f77da38',
|
196
|
+
|
197
|
+
'http://localhost/php_test/iNTO/iNTO.php'
|
198
|
+
|
199
|
+
);
|
200
|
+
|
201
|
+
$api = new SpotifyWebAPI\SpotifyWebAPI();
|
202
|
+
|
203
|
+
if (isset($_GET['code'])) {
|
204
|
+
|
205
|
+
$session->requestAccessToken($_GET['code']);
|
206
|
+
|
207
|
+
$api->setAccessToken($session->getAccessToken());
|
208
|
+
|
209
|
+
}else{
|
210
|
+
|
211
|
+
header('Location: ' . $session->getAuthorizeUrl(array(
|
212
|
+
|
213
|
+
'scope' => array(
|
214
|
+
|
215
|
+
'playlist-read-private', // プレイリスト取得
|
216
|
+
|
217
|
+
'playlist-modify-private', // プレイリスト変更
|
218
|
+
|
219
|
+
'user-read-private',
|
220
|
+
|
221
|
+
'playlist-modify'
|
222
|
+
|
223
|
+
)
|
224
|
+
|
225
|
+
)));
|
226
|
+
|
227
|
+
die();
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
///////////ここまでアクセストークンの処理
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
$profileInfo = $api->me(); //認証したユーザのプロフィール
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
//プロフィールから名前を取得
|
240
|
+
|
241
|
+
$this->userName = $profileInfo->display_name;
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
//プレイリスト取得
|
246
|
+
|
247
|
+
$this->playlists = $api->getMyPlaylists(["limit" => 2]);
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
//プロフィール画像をプロフィールから取得
|
252
|
+
|
253
|
+
$this->profilePic = $profileInfo->images[0]->url;
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
//トップトラックを取得
|
258
|
+
|
259
|
+
$this->topTracks = $api->getMyTop('tracks',['limit' => 3]);
|
260
|
+
|
261
|
+
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
|
266
|
+
|
267
|
+
public function getBio(){
|
268
|
+
|
269
|
+
return $this->bio;
|
270
|
+
|
271
|
+
}
|
272
|
+
|
273
|
+
|
274
|
+
|
275
|
+
public function getUserName(){
|
276
|
+
|
277
|
+
return $this->userName;
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
|
282
|
+
|
283
|
+
public function getPlaylists(){
|
284
|
+
|
285
|
+
return $this->playlists;
|
286
|
+
|
287
|
+
}
|
288
|
+
|
289
|
+
|
290
|
+
|
291
|
+
public function getProfilePic(){
|
292
|
+
|
293
|
+
return $this->profilePic;
|
294
|
+
|
295
|
+
}
|
296
|
+
|
297
|
+
|
298
|
+
|
299
|
+
public function getFollower(){
|
300
|
+
|
301
|
+
return $this->follower;
|
302
|
+
|
303
|
+
}
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
public function getFollow(){
|
308
|
+
|
309
|
+
return $this->follow;
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
|
314
|
+
|
315
|
+
public function getTopTracks(){
|
316
|
+
|
317
|
+
return $this->topTracks;
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
public function setBio($bio){
|
324
|
+
|
325
|
+
//$bioは文字列か確かめる
|
326
|
+
|
327
|
+
$this->bio = $bio;
|
328
|
+
|
329
|
+
}
|
38
330
|
|
39
331
|
}
|
40
332
|
|
41
333
|
|
42
334
|
|
43
|
-
|
335
|
+
?>
|
44
|
-
|
45
|
-
|
46
336
|
|
47
337
|
```
|
48
338
|
|
49
339
|
### エラーメッセージ
|
50
340
|
|
51
|
-
```php
|
52
|
-
|
53
|
-
Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: An unknown error occurred. in C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php:52 Stack trace: #0 C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php(242): SpotifyWebAPI\Request->parseBody(NULL, 403) #1 C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php(121): SpotifyWebAPI\Request->send('GET', 'https://api.spo...', 'limit=3&offset=...', Array) #2 C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\iNTO\spotify-web-api-php-master\src\SpotifyWebAPI.php(1054): SpotifyWebAPI\Request->api('GET', '/v1/me/top/trac...', Array, Array) #3 C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\iNTO\profile.php(52): SpotifyWebAPI\SpotifyWebAPI->getMyTop('tracks', Array) #4 C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\iNTO\iNTO.php(16): Profile->__construct() #5 {main} thrown in C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php on line 52
|
54
|
-
|
55
341
|
```
|
56
342
|
|
343
|
+
Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException:
|
344
|
+
|
345
|
+
An unknown error occurred.
|
346
|
+
|
347
|
+
in C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php:52 Stack trace: #0
|
348
|
+
|
349
|
+
C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php(242): SpotifyWebAPI\Request->parseBody(NULL, 403) #1
|
350
|
+
|
351
|
+
C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php(121): SpotifyWebAPI\Request->send('GET', 'https://api.spo...', 'limit=3&offset=...', Array) #2
|
352
|
+
|
353
|
+
C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\iNTO\spotify-web-api-php-master\src\SpotifyWebAPI.php(1054): SpotifyWebAPI\Request->api('GET', '/v1/me/top/trac...', Array, Array) #3 C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\iNTO\profile.php(52): SpotifyWebAPI\SpotifyWebAPI->getMyTop('tracks', Array) #4
|
354
|
+
|
355
|
+
C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\iNTO\iNTO.php(16): Profile->__construct() #5
|
356
|
+
|
357
|
+
{main} thrown in C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php on line 52
|
358
|
+
|
359
|
+
```
|
360
|
+
|
57
361
|
|
58
362
|
|
59
363
|
|
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -16,10 +16,6 @@
|
|
16
16
|
|
17
17
|
```php
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
//トップトラックを取得
|
22
|
-
|
23
19
|
class Profile{
|
24
20
|
|
25
21
|
private $topTracks;
|
@@ -28,13 +24,15 @@
|
|
28
24
|
|
29
25
|
public function __construct() {
|
30
26
|
|
31
|
-
//アクセストークンの処理
|
27
|
+
//アクセストークンの処理を行う
|
32
28
|
|
33
29
|
|
34
30
|
|
35
31
|
$api->new SpotifyWebAPI\SpotifyWebAPI();
|
36
32
|
|
37
33
|
|
34
|
+
|
35
|
+
//トップトラックの取得
|
38
36
|
|
39
37
|
$this->topTracks = $api->getMyTop('tracks',['limit' => 3, 'offset' => 1,]);
|
40
38
|
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -42,11 +42,21 @@
|
|
42
42
|
|
43
43
|
|
44
44
|
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
45
49
|
```
|
46
50
|
|
47
51
|
### エラーメッセージ
|
48
52
|
|
53
|
+
```php
|
54
|
+
|
49
55
|
Fatal error: Uncaught SpotifyWebAPI\SpotifyWebAPIException: An unknown error occurred. in C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php:52 Stack trace: #0 C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php(242): SpotifyWebAPI\Request->parseBody(NULL, 403) #1 C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php(121): SpotifyWebAPI\Request->send('GET', 'https://api.spo...', 'limit=3&offset=...', Array) #2 C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\iNTO\spotify-web-api-php-master\src\SpotifyWebAPI.php(1054): SpotifyWebAPI\Request->api('GET', '/v1/me/top/trac...', Array, Array) #3 C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\iNTO\profile.php(52): SpotifyWebAPI\SpotifyWebAPI->getMyTop('tracks', Array) #4 C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\iNTO\iNTO.php(16): Profile->__construct() #5 {main} thrown in C:\TECHBASE\__WatchOut__\XAMPP\htdocs\php_test\vendor\jwilsson\spotify-web-api-php\src\Request.php on line 52
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
|
50
60
|
|
51
61
|
|
52
62
|
|