Skip to content

Instantly share code, notes, and snippets.

@yasuharu519
Last active August 29, 2015 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasuharu519/45a517e1a0f03e68c8a0 to your computer and use it in GitHub Desktop.
Save yasuharu519/45a517e1a0f03e68c8a0 to your computer and use it in GitHub Desktop.
Instagramの猫画像クローラ crawl_instagram.cpp
#include <fstream>
#include <iostream>
#include <string>
#include <restclient-cpp/restclient.h>
#include "json11.hpp"
static std::string client_id = "クライアントID";
static std::string endpoint = "https://api.instagram.com/v1/tags/cat/media/recent?client_id=" + client_id;
int main()
{
auto res = RestClient::get(endpoint);
std::string err;
auto json = json11::Json::parse(res.body, err);
if(!err.empty())
{
std::cout << err << std::endl;
return 1;
}
auto data = json["data"].array_items();
for(auto& item : data)
{
auto id = item["id"].string_value();
auto url = item["images"]["standard_resolution"]["url"].string_value();
std::cout << url << std::endl;
auto raw = RestClient::get(url);
std::ofstream out(id + ".jpg");
out << raw.body;
out.close();
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment