【发布时间】:2016-04-13 20:04:02
【问题描述】:
我在 java 中编写了创建包装器实例并验证用户帐户的电子邮件和密码的代码,但是由于停止支持 java SoundCloud API,我似乎无法找到获取用户的方法' 从这一点开始喜欢,我已经查看了所有文档和示例,但在实施时似乎都没有。
PS。为了安全起见,我更改了客户端 ID、客户端密码以及用户名和密码,因此请忽略代码中的内容。
import com.soundcloud.api.ApiWrapper;
import com.soundcloud.api.Token;
import java.io.File;
/**
* Creates an API wrapper instance, obtains an access token and serializes the
* wrapper to disk. The serialized wrapper can then be used for subsequent
* access to resources without re-authenticating
*
* @see GetResource
*/
public final class CreateWrapper {
public static final File WRAPPER_SER = new File("wrapper.ser");
public static void main(String[] args) throws Exception {
final ApiWrapper soundCloud = new ApiWrapper(
"client_id", /*client id*/
"client_secret" /* client_secret */,
null /* redirect URI */,
null /* token */);
Token token;
token = soundCloud.login("username@username.com" /* login */, "password" /* password */);
System.out.println("got token from server: " + token);
// in this example the whole wrapper is serialised to disk -
// in a real application you would just save the tokens and usually have the client_id/client_secret
// hardcoded in the application, as they rarely change
soundCloud.toFile(WRAPPER_SER);
System.out.println("wrapper serialised to " + WRAPPER_SER);
}
}
【问题讨论】:
标签: java api wrapper soundcloud