在iOS中请求Spotify
我正在尝试使用Spotify的WebAPI从我的应用程序中搜索特定的歌曲。到目前为止,在代码方面,我有:在iOS中请求Spotify,ios,spotify,nsurlrequest,Ios,Spotify,Nsurlrequest,我正在尝试使用Spotify的WebAPI从我的应用程序中搜索特定的歌曲。到目前为止,在代码方面,我有: NSString *theReplacement = @"cant+stop+the+feeling"; NSURLResponse *response; NSError *error; NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.spo
NSString *theReplacement = @"cant+stop+the+feeling";
NSURLResponse *response;
NSError *error;
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"https://api.spotify.com/v1/search?q=%@&type=track", theReplacement]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseStr = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(@"%@", response);
但Console只是给了我这个,我希望在其中的某个地方有一个外部spotify url来显示:
注意有时控制台会给我(null),有时它只是挂断请求。WebAPI控制台向我展示了这样的GET。在iOS中我将如何做到这一点
curl -X GET "https://api.spotify.com/v1/search?q=can't+stop+the+feeling&type=track" -H "Accept: application/json"
这是控制台
{ URL: https://api.spotify.com/v1/search?q=cant+stop+the+feeling&type=track } { status code: 200, headers {
"Access-Control-Allow-Credentials" = true;
"Access-Control-Allow-Headers" = "Accept, Authorization, Origin, Content-Type";
"Access-Control-Allow-Methods" = "GET, POST, OPTIONS, PUT, DELETE";
"Access-Control-Allow-Origin" = "*";
"Access-Control-Max-Age" = 604800;
"Cache-Control" = "public, max-age=7200";
Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Type" = "application/json; charset=utf-8";
Date = "Sat, 23 Jul 2016 05:29:40 GMT";
"Keep-Alive" = "timeout=600";
Server = nginx;
"Strict-Transport-Security" = "max-age=31536000;";
"Transfer-Encoding" = Identity;
"X-Content-Type-Options" = nosniff;
} }