阅读背景:

如何通过Unity连接移动应用程序从Soundcloud接收回调

来源:互联网 

I have an app made in Unity that let you mix a song. I'm working on a "upload to Soundcloud" button to include in this app for both Android and iOS.

我有一个Unity制作的应用程序,可以让你混合一首歌。我正在制作一个“上传到Soundcloud”按钮,以便在此应用中包含Android和iOS。

I have trouble receiving a response from Soundcloud after directing the user to the "Connect" window of SoundCloud. I use something like this to open the Soundcloud connection page. The browser is opened correctly and I can sign in using this.

在将用户定向到SoundCloud的“连接”窗口后,我无法收到Soundcloud的响应。我使用这样的东西来打开Soundcloud连接页面。浏览器正确打开,我可以使用此登录。

    Application.OpenURL("https://soundcloud.com/connect?"
            + "client_id=[my_client_id]"
            + "&redirect_uri=my.app://callback"
            + "&display=popup"      
            + "&response_type=token"
            + "&scope=non-expiring");

I have created a custom scheme for both my iOS and Android app to redirect to my app after the connection. That is working too, my app is reopened after clicking on "Connect" in the Soundcloud page.

我为我的iOS和Android应用程序创建了一个自定义方案,以便在连接后重定向到我的应用程序。这也有效,我的应用程序在Soundcloud页面中单击“连接”后重新打开。

I now need an authentication code or token to request an access token to be able to upload my song. But after being redirect in my app, I don't know what to do to receive the authentication code. It must have something to do with the ://callback link, but I didn't find how to get it. Do I need to make platform specific code for that?

我现在需要一个身份验证代码或令牌来请求访问令牌能够上传我的歌曲。但在我的应用程序中重定向后,我不知道该怎么做才能收到身份验证代码。它必须与://回调链接有关,但我没有找到如何获取它。我需要为此制作特定于平台的代码吗?

Any help would be appreciated!

任何帮助,将不胜感激!

2 个解决方案

#1


0  

The callback should include a code for you to use to create a token

回调应包含您用于创建令牌的代码

The callback URL when called will have a code attached to it :

调用时的回调URL将附加一个代码:

https://YOUR_CALLBACK_URL?code=CODE_RETURNED_FROM_SOUNDCLOUD

Once you have extracted the code returned from the url, you can then use that to make a request to soundcloud to get an authorization token

一旦提取了从url返回的代码,就可以使用它来向soundcloud发出请求以获取授权令牌

Example request using curl (using PHP)

使用curl的示例请求(使用PHP)

curl -X POST 'https://api.soundcloud.com/oauth2/token' 
-F 'client_id=YOUR_CLIENT_ID' 
-F 'client_secret=YOUR_CLIENT_SECRET' 
-F 'grant_type=authorization_code' 
-F 'redirect_uri=YOUR_CALLBACK_URL' 
-F 'code=THE_VALUE_OF_THE_CODE_RETURNED'


$data = array(
  'code' => VALUE_OF_THE_CODE_RETURNED,
  'client_id' => YOUR_CLIENT_ID,
  'client_secret' => YOUR_CLIENT_SECRET,
  'redirect_uri' => YOUR_CALLBACK_URL,
  'grant_type' => 'authorization_code'
);

I use the following options with curl

我使用curl的以下选项

  curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_HEADER, true);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  curl_setopt($ch, CURLOPT_VERBOSE, 1);

If successful you should receive something like this (example is JSON)

如果成功,你应该收到这样的东西(例如JSON)

{
"access_token":"ACCESS_TOKEN_VALUE",
"expires_in":21599,
"scope":"*",
"refresh_token":"REFRESH_TOKEN_VALUE"
}

#2


0  

Thanks SteveE for your reply but it wasn't my problem.

感谢SteveE的回复,​​但这不是我的问题。

The problem was that I needed a Deep Linking implementation for both my Android and iOS app to receive the callback from Soundcloud. I needed something to catch the intent in the onCreate method, which contains the data send by Soundcloud, on Android and to catch the calls to application:openURL:options: du UIApplicationDelegate on iOS.

问题是我需要一个Deep Linking实现我的Android和iOS应用程序才能从Soundcloud接收回调。我需要一些东西来捕捉onCreate方法中的意图,该方法包含Soundcloud在Android上发送的数据,并捕获对应用程序的调用:openURL:options:du UIApplicationDelegate on iOS。

To do this, we needed native plugins for both platforms and now we can receive the Soundcloud callback and check our authorization code to continue the process of uploading the song.

为此,我们需要两个平台的本机插件,现在我们可以接收Soundcloud回调并检查我们的授权代码以继续上传歌曲的过程。


分享到: