Jeveuxcréerunevariable de session du site last.fm
j'aifaisça:
String key = "5f114bd222884e3fd9208742329930bb";
String token=Authenticator.getToken(key);
String secret="e35ca1b33371e9f9097d56b31c2cf196";
String api_sig = encode("api_key" + key + "methodauth.getSessiontoken" + token + secret);
Session session = Authenticator.getSession(token,key, api_sig);
System.out.println("url: http://ws.audioscrobbler.com/2.0/?method=auth.getSession&token="+token+"&api_key="+key+"&api_sig="+api_sig);
System.out.println("session="+session);
}
et j'ai eu le resulta suivant:
20 mars 2014 00:26:57 de.umass.lastfm.Caller openConnection
INFO: Open connection: http://ws.audioscrobbler.com/2.0/
20 mars 2014 00:26:58 de.umass.lastfm.Caller openPostConnection
INFO: Post body: method=auth.getToken&api_key=5f114bd222884e3fd9208742329930bb
20 mars 2014 00:26:58 de.umass.lastfm.Caller openConnection
INFO: Open connection: http://ws.audioscrobbler.com/2.0/
20 mars 2014 00:26:58 de.umass.lastfm.Caller openPostConnection
INFO: Post body: method=auth.getSession&token=f2219e06cf9f8c5ae65e9c84288db5e6&api_key=5f114bd222884e3fd9208742329930bb&api_sig=ee0e0ab8b2dc5f162072441b44294b13
20 mars 2014 00:26:58 de.umass.lastfm.Caller call
ATTENTION: API call failed with result: Result[isSuccessful=false, errorCode=13, httpErrorCode=-1, errorMessage=
Invalid method signature supplied
, status=FAILED]
url: http://ws.audioscrobbler.com/2.0/?method=auth.getSession&token=f2219e06cf9f8c5ae65e9c84288db5e6&api_key=5f114bd222884e3fd9208742329930bb&api_sig=e8ba399cfaa33073ff991d07ddbfb2e0
session=null
et quand je tape sur le navigateur l'addresse:
http://ws.audioscrobbler.com/2.0/?method=auth.getSession&token=f2219e06cf9f8c5ae65e9c84288db5e6&api_key=5f114bd222884e3fd9208742329930bb&api_sig=e8ba399cfaa33073ff991d07ddbfb2e0
j'aurais:
<lfm status="failed">
<error code="14">This token has not been authorized</error>
</lfm>
1 - 我的设置没问题,但我的会话为空 2-in控制台:上面发布的网址与我在Systeme.out.println中所获得的网址不同,交换api_sig 3-in控制台我错误代码= 13:无效的签名提供方法和导航器错误代码= 14:此令牌没有自动化
你可以帮帮我吗?答案 0 :(得分:0)
如果您要创建Web服务,则不应在代码中执行Authenticator.getToken(key),您必须将用户重定向到该页面:“http://www.last.fm/api/auth/?api_key=”+ key +“&amp; cb =”+ callBackUrl 。并且令牌将由callBackUrl发回。
答案 1 :(得分:0)
这意味着您首先需要允许应用程序访问用户帐户,例如在Web浏览器中。之后,令牌将有效用于构建签名并获取会话密钥。