0

下面是我拥有的代码,而不是自动将信息添加到 ID 为 #userid 的 div,我需要实际打印出用户 ID(目前,它只是将其添加到 div,但我需要能够只需在我想要的任何地方打印它,而不是自动添加到 div 包装中)。

我的最终目标是获取用户 ID,然后将其放入 WordPress 查询中(用户 ID 目前被用作帖子标签,我需要从该特定用户那里提取所有帖子,所以我想按标签查询帖子)

<script src="http://connect.soundcloud.com/sdk.js"></script>  
<script>
  SC.initialize({
    client_id: "a808af7fabb53ad7971c6c9675f392b3",
    redirect_uri: "http://madebyguerrilla.com/clients/2012/theappreciationengine/wordpress/wp-content/themes/TheAppreciationEngine_WP/callback.html"
  });

  $("#connect").live("click", function(){
    SC.connect(function(){
      SC.get("/me", function(me){
        $("#username").text(me.username);
        $("#userid").text(me.id);
      });
    });
  });

  $("#update").live("click", function(){
    SC.put("/me", {user: {description: $("#description").val()}}, function(response, error){
      if(error){
        alert("Some error occured: " + error.message);
      }else{
        alert("Profile description updated!");
      }
    });
  });
</script>

任何帮助,将不胜感激。

4

1 回答 1

0

你有机会成为 JS 的新手吗?只是在开玩笑。

SC.get()通话中,您可以通过以下方式访问 ID me.id

var userId;

SC.get("/me", function(me){
    $("#username").text(me.username);
    $("#userid").text(me.id); // <-- This is the user id, you can store it in a variable
    userId = me.id; //           <-- like this
});
于 2012-09-24T17:27:24.400 回答