【问题标题】:GET data from GitHub is Possible, GET data from dribbble doesn't work从 GitHub 获取数据是可能的,从 dribbble 获取数据不起作用
【发布时间】:2015-04-16 16:48:09
【问题描述】:

我已经使用这段代码从 GitHub API 获取数据

var name;
var description;    
var html_url;
var username    = "PirateStef";
var updated_at;
var language;       
var repo;
var urlGitHub       = 'https://api.github.com/users/'+username+'/repos?sort=created';

$.getJSON(urlGitHub, function(json){
    repositories = json;
    outputGitHubContent();      // GitHub Content         
}); 

function outputGitHubContent() {


    $.each(repositories, function(index){
        name            = "<div class='name'>" + repositories[index].name + "</div>";
        description     = "<div class='description'>" + repositories[index].description + "</div>";
        updated_at      = "<div class='updated_at'>" + repositories[index].updated_at.substring(0,10) + "</div>";
        html_url        = "<a class='html_url'  target='_blank' href='" + repositories[index].html_url + "'>";
        language        = "<div class='language'>" + repositories[index].language + "</div>";

        repo            = "<div class='repo'>" + html_url + "<div>" + name + language +  "</div>" + description + updated_at + "</a> </div>";

        console.log(repositories[index].owner.login);

        $("#github").append(repo);
    });
};

这是 Github API 网址

https://api.github.com/users/PirateStef/repos?sort=updated

我尝试构建一个函数来获取运球数据。使用下面的 api.dribbble 网址。

http://api.dribbble.com/players/PirateStef/shots/

我无法从每个对象中获取“标题”。


无效的运球代码

var urlDribbble     = 'http://api.dribbble.com/players/'+username+'/shots/';
var shot;   

$.getJSON(urlDribbble, function(json){
    shots = json;
    outputDribbbleContent();    // Dribbble Content         
}); 

function outputDribbbleContent() {


    $.each(shots, function(index){
        console.log(shots[index].title);
    });
};

让我 5 倍未定义

console.log(shots[index]);

给我这个

[
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
, 
Object
]

【问题讨论】:

  • 什么是dribble.com?它看起来像一个未使用的登录页面。为什么您希望为一个网站设计的 API 调用可以在另一个网站上运行?
  • 如果 API 没有启用 CORS 或 jsonp,则并非所有 API 都可以通过 ajax 获得...查看 API 文档。还有一些需要在请求中授权
  • 不是绝对的,但可能是的。阅读 API 文档
  • “我无法从每个对象中获取“标题””是什么意思?您是否收到响应,但无法解析它?如果是这样,响应是什么样的? API 请求是否完全失败?您是否看到任何错误消息?
  • @user3199999,所以您收到了回复。您的代码可能有问题。请向我们展示 工作的 Dribbble 代码,而不是显示有效的 GitHub 代码。

标签: jquery json github get


【解决方案1】:

我知道答案有点晚了,但我最近在 dribbble 的某些部分工作并开始了解这些:

'https://api.dribbble.com/v1/users/'+user_id+'/buckets?access_token='+dribbble_access_token

这将提供用户存储桶数据:

created_at
说明
身份证
名称
拍摄次数
更新时间

现在开始拍摄您可以使用的照片:

'https://api.dribbble.com/v1/buckets/'+bucket_id+'/shots?access_token='+dribbble_access_token

'https://api.dribbble.com/v1/users/'+user_id+'/shots?access_token='+dribbble_access_token

这将提供 12(默认)拍摄数据以及所有可能的分辨率图像。 虽然我仍在寻找任何参数来管理限制,即默认情况下为 12。

好的,我也找到了设置限制的解决方案。要传递的参数是

每页

这可以接收任何数值。所以我的最终网址是:

'https://api.dribbble.com/v1/users/'+user_id+'/shots?per_page='+limit+'&access_token='+dribbble_access_token

我在 Joomla 的一个漂亮的 Multi social tabs 模块中使用了它 由Webkul 关注,然后关注link 只需在此处查看运球标签

【讨论】:

    【解决方案2】:

    我用的是jribbble插件,这样我就不用在dribbble上注册应用了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-08-18
      • 2014-06-09
      • 2022-07-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多