2013-03-28 2 views
1

Spotify API 1.x 시도 중. 내Spotify API 1.x 사용자 세션 가져 오기

"Dependencies": { 
     "api": "1.20.1", 
     "views": "1.24.1" 
    } 

매니페스트 갖는 문제는 새로운 스포티 파이 API와 현재의 세션을 받고. Session Docs

후 나는이와 사용자 정보를 가지고 잠시 :

require(['$api/models','$api/models#User','$api/models#Session'], function(models) { 
    var user = models.User.fromURI('spotify:user:@'); 
    user.load('username', 'name').done(function(u) { 
     userUid = u.identifier; 
    }); 
}); 

을하지만 models.Session보고 부하 방법 (점점 던져 오류)와이없는 세션 난 못해 어떤 값이라도? 예를 들어, 지금은 세션에서 정보를 얻을 수 있습니다

"api": "1.3.0" 

내 국가 : :(

답변

1

내가에 manifest.json API 버전에서 변경

var userCountry = models.session.country; 
1

을 나는 약간 오해의 소지가 스포티 파이 문서를 찾을 수 세션에 관해서. 나는 시행 착오와 인터넷 검색에서 문서보다는 오히려 발견 한 많은 것들이있다.

@Backer와 마찬가지로, ch API 버전을 1.3.0 이상으로 설정하십시오 (사용 가능한 경우). 이 기능을 사용하려면 Spotify를 다시 시작해야합니다..

그런 다음이 같은 세션 개체에 액세스 할 수 있습니다 (여기서, "세션" 소문자를해야합니다) :

models.session.load('product','connection','device','user').done(function(s){ 
    console.log('sess:',s) 
}); 

사용자 개체는 이것의 일부가 될 것입니다,하지만 채워지지 않습니다 로드하지 않는 한 속성이 있습니다.

require([ 
'$api/models','$api/models#Session' 
], function(models) { 
app.user = {}; 
    models.session.load('product','connection','device','user').done(function(sess){ 
     sess.user.load('name', 'username', 'subscribed').done(function(user){ 
      app.user.name = user.name; // string 
      app.user.username = user.username; // string 
      app.user.subscribed = user.subscribed; // boolean 
     }); 
     app.user.connection = sess.connection; // string 
     app.user.country = sess.country; // string ISO-2 
     app.user.device = sess.device; // string 
     app.user.language = sess.language; // string ISO-2 
     app.user.product = sess.product; // string 

    }); 
}); 

전체 세션 개체 :

Session 
_done: 65535 
_listening: true 
_ob: Object 
_obcount: 1 
_requestArgs: Array[0] 
_requestName: "session_event_wait" 
capabilities: Object 
connecting: false 
connection: "wlan" 
country: "SE" 
developer: true 
device: "desktop" 
incognito: false 
language: "en" 
online: true 
product: "open" 
resolution: 1 
streaming: "enabled" 
testGroup: 000 
user: User 
    _done: 255 
    currentUser: true 
    identifier: "longcodehere" 
    image: "http://profile-images.scdn.co/artists/default/anotherlongcodehere" 
    images: Array[2] 
    name: "My Name" 
    subscribed: false 
    uri: "spotify:user:@" 
    username: "myusername" 
    __proto__: c 
    __proto__: c 
다음 세션에서 속성과 사용자의 부분 집합을 검색하는 예입니다
관련 문제