Last active
August 29, 2015 14:13
-
-
Save yasuharu519/45a517e1a0f03e68c8a0 to your computer and use it in GitHub Desktop.
Instagramの猫画像クローラ crawl_instagram.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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