这样做的目的是自动将归因链接添加到博客文章中使用的图像。我有一个demo set up here,它可以手动使用flickr.photos.getInfo在图像上建立归因URL。

为此,我从CSS中的background-image取得了照片ID,并创建了API调用。我想做的是自动从background-image网址中提取照片ID(此示例为3990985751),以在每个帖子上创建API调用。

的CSS

.featured {
background-image:url('https://farm3.staticflickr.com/2613/3990985751_7ca0769f15_b.jpg');
}


的HTML

<div class="featured">
<body>
    <div class="featured">
      <div id="featured-credit">
        <p id="credits"></p>
      </div>
    </div>
  </div>


jQuery / JS

// Builds the URL to link in the image credit
      function jsonFlickrApi (response) {
        $("#credits").html('<a href="http://www.flickr.com/photos/'+response.photo.owner.nsid+'/'+response.photo.id+'/" target="blank">'+response.photo.title._content+"</a>");
      }

      // removes the CSS formatting for the featured image background URL
      function extractUrl(input) {
        return input.replace(/"/g,"").replace(/url\(|\)$/ig, "");
      }

    /* After all the scripts are loaded, send the featured photo to the Flickr API to get the JSON data */
    <script src="https://api.flickr.com/services/rest/?method=flickr.photos.getInfo&api_key=APIKEYHERE&photo_id=3990985751&format=json&jsoncallback=?"></script>


我在SO和其他网站上进行了大量研究,发现其他解决方案都使用配置文件URL,而我需要使用静态源URL。任何帮助表示赞赏。

最佳答案

您是否尝试过对闪烁进行ajax调用?

$.ajax({
    url: "https://api.flickr.com/services/rest/",
    type: 'GET',
    contentType: "application/json;charset=utf-8",
    data:{
        method: 'flickr.photos.getInfo',
        api_key: 'c8c95356e465b8d7398ff2847152740e',
        format: 'json',
        photo_id: yourPhotoID,
    },
    success: function(data){
        //data is the response from flickr
    }
});

08-19 05:20