2

アプリケーションの SoundCloud API に問題があります。トラックへのリンクを取得するアプリを作成し (たとえば、このhttp://api.soundcloud.com/tracks/48760960のようなもの)、後で SCAudioStream を使用して再生できる stream_url を取得します。ユーザーの認証はありません。アプリのクライアント 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

私は何を間違っていますか?

4

2 に答える 2

2

私は問題を理解しました。公式サイトから SC API をダウンロードし、最新の SC API をインストールするだけです。次に、次のようにします。

- (void)searchStreamURLByTrackID: (NSString *)trackID
{
NSString *string = [NSString stringWithFormat:@"https://api.soundcloud.com/tracks/%@.json?client_id=%@", trackID, kSCClientID];

[SCRequest performMethod: SCRequestMethodGET 
              onResource: [NSURL URLWithString:string]
         usingParameters: nil 
             withAccount: nil
  sendingProgressHandler: nil 
         responseHandler:^(NSURLResponse *response, NSData *data, NSError *error){

                                      NSString *resultString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
                                      NSLog(@"FOUND:\n%@", resultString);
                              }
                      ];

}

その後、resultString の JSON からストリーム URL を取得します。

最後に、次のコードを記述する必要があります。

NSString *streamURL = [(NSDictionary *)jsonData objectForKey:@"stream_url"];
NSString *realURL = [streamURL stringByAppendingFormat:@".json?client_id=%@", kSCClientID];
AVPlayer *player = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:realURL]];

楽しみ!

于 2012-07-02T19:01:06.177 に答える
0

https://github.com/soundcloud/CocoaSoundCloudAPIを確認しましたか? これは API ラッパーの最新バージョンです (iOS 3.0 のサポートが不要な場合)。また、チュートリアル ビデオも付属しています: http://vimeo.com/28715664

このライブラリを使い続けたい場合は、ログ メッセージ ("auth ready with ...") が表示される場所を見つけてください。AuthorizationDelegate メソッドを実装しましたか? https://github.com/soundcloud/cocoa-api-wrapper/blob/master/Usage.md#the-authentication-delegate-the-easy-wayを参照してください

于 2012-06-21T00:41:08.597 に答える