我的应用程序中有 SoundCloud API 的问题。我创建了一个应用程序,获取指向曲目的链接(例如,类似http://api.soundcloud.com/tracks/48760960的内容)并获取 stream_url,稍后可以使用 SCAudioStream 播放。用户没有身份验证,我只使用我的应用程序的客户端 ID 和客户端密码。应用程序已注册。
我以这种方式创建 soundCloudManager:
- (id)init
{
if(self = [super init])
{
conf = [SCSoundCloudAPIConfiguration configurationForProductionWithClientID: kSCClientID
clientSecret: kSCClientSecret
redirectURL: kSCRedirectURL];
conf.accessTokenURL = kSCAccessTokenURL;
api = [[SCSoundCloudAPI alloc] initWithDelegate: self
authenticationDelegate: self
apiConfiguration: conf];
//[api checkAuthentication];
}
return self;
}
如果取消注释 [api checkAuthentication],则日志将显示下一个:
“使用 URL 进行身份验证:https://soundcloud.com/connect?client_id=&redirect_uri=&response_type=code”
然后我调用这个方法从轨道获取数据:
- (void)runSearchingStreamWithTrackID: (NSString *)trackID
{
[api performMethod: @"GET"
onResource: @"tracks"
withParameters: [NSDictionary dictionaryWithObject:trackID forKey:@"ids"]
context: @"trackid"
userInfo: nil];
}
然后这个委托的方法调用:
- (void)soundCloudAPI:(SCSoundCloudAPI *)soundCloudAPI
didFailWithError:(NSError *)error
context:(id)context
userInfo:(id)userInfo
错误文本:
“HTTP 错误:401”。
是未经授权的意思。但为什么?我是否应该被授权为 soundCloud 用户以获取有关曲目的信息?
我将它用于 SoundCloudAPI: https ://github.com/soundcloud/cocoa-api-wrapper
请帮忙!:(
今天我修好了。我只是将此方法添加到 init :
[api authenticateWithUsername:kLogin password:kPwd];
之后调用此方法:
- (void)soundCloudAPIDidAuthenticate
所以,这个测试账号被授权了。
然后我调用这个方法:
- (void)runSearchingStreamWithTrackID: (NSString *)trackID
{
[api performMethod: @"GET"
onResource: @"tracks"
withParameters: [NSDictionary dictionaryWithObject:trackID forKey:@"ids"]
context: @"trackid"
userInfo: nil];
}
并且不会调用这些方法中的任何一个:
- (void)soundCloudAPI:(SCSoundCloudAPI *)soundCloudAPI
didFailWithError:(NSError *)error
context:(id)context
userInfo:(id)userInfo;
- (void)soundCloudAPI:(SCSoundCloudAPI *)soundCloudAPI
didFinishWithData:(NSData *)data
context:(id)context
userInfo:(id)userInfo;
- (void)soundCloudAPIDidAuthenticate;
- (void)soundCloudAPIDidResetAuthentication;
- (void)soundCloudAPIDidFailToGetAccessTokenWithError:(NSError *)error;
- (void)soundCloudAPIPreparedAuthorizationURL:(NSURL *)authorizationURL;
但是有日志:
-[NXOAuth2PostBodyStream open] Stream has been reopened after close
这个方法被称为:
[NXOAuth2Client oauthConnection:connection didFailWithError:error];
error: HTTP 401
我错了什么?