Deni2312 InstagramAPI Save Abandoned

C++17 header only Instagram API

Project README

C++ Instagram API

A header-only version of Instagram Private API in C++

Getting started.

This API has been tested on Linux and Windows.

  • Minimum requirements
    • C++20
    • CMake 3.8+

Linux / Windows

First we need to install dependencies through vcpkg:

  • Dependencies
    • nlohmann-json
    • cpr

On Linux you can use the install.sh file or install libraries manually(the same for Windows):

git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
./bootstrap-vcpkg.sh
./vcpkg install nlohmann-json
./vcpkg install cpr
./vcpkg integrate install

With CMake:

cd InstagramAPI
mkdir build
cmake -B build/ -S . -DCMAKE_TOOLCHAIN_FILE=vcpkgdirectory/scripts/buildsystems/vcpkg.cmake
cd build
cmake --build .
./Instagram

Change vcpkgdirectory with the relative or absolute path of vcpkg.

Writing your first bot

Hello World!

#include "include/Instagram.h"

int main()
{
	Instagram instagram{"username", "password"};
	try {
		instagram.login();
	}
	catch (Network::Error& e) {
		std::cerr << e.what();
	}
}


General API Documentation

Usage

All the operations that contains information returned by Instagram are typed.
This implementation has all basic methods, here's a list of them:

	void login();
	void remove_profile_picture();
	void set_private();
	void set_public();
	void follow(const std::string& user_id);
	void unfollow(const std::string& user_id);
	void block(const std::string& user_id);
	void remove_follower(const std::string& user_id);
	void unblock(const std::string& user_id);
	void comment_like(const std::string& comment_id);
	void comment_unlike(const std::string& comment_id);
	void media_like(const std::string& media_id);
	void media_unlike(const std::string& media_id);
	void comment(const std::string& media_id,const std::string& comment_text);
	IgTypes::UserCommentsRequest comments(const std::string& media_id);
	IgTypes::UserListRequest get_user_following(const std::string& user_id);
	IgTypes::UserListRequestFollow get_user_followers(const std::string& user_id);
	IgTypes::UserFeedRequest get_user_feed(const std::string& user_id);
	IgTypes::UserRequest search_username(const std::string& username);
	void setProxy(const std::string& type,const std::string& address);


There's an example:

#include "include/Instagram.h"
#include <iostream>
#include <string>

int main()
{
	Instagram instagram{"username", "password"};
	try{
		instagram.login();
	}
	catch(Network::Error& e){
		std::cerr<<e.what();
	}
	//Get user id
	auto user_id=*instagram.search_username("username").get_user()->get_pk();
	//Get user feed like photos or videos
	auto feed=instagram.get_user_feed(std::to_string(user_id));
	//Iterate feed
	for(auto item : *feed.get_items()){
		//Print item id
		auto id=*item.get_id();
		std::cout<<"id: "+id;
		//Like post
		instagram.media_like(id);
		//Unlike post
		instagram.media_unlike(id);
		//Comment post
		instagram.comment(id,"hello");
		//Get comment
		auto comment=instagram.comments(id);
	}
	//Set profile private
	instagram.set_private();
	//Get followers
	auto followers=instagram.get_user_followers(std::to_string(user_id));
	for(auto follower: *followers.get_users()){
		//print username
		std::cout<<*follower.get_username();
	}
	//Follow user
	instagram.follow(std::to_string(user_id));
	//Set proxy, type would be http or https
	instagram.setProxy("http","proxy.com");
}


Error Handling

To handle errors catch Network::Error &e and the output of e.what() will be the JSON error returned by instagram.

Open Source Agenda is not affiliated with "Deni2312 InstagramAPI" Project. README Source: deni2312/InstagramAPI
Stars
43
Open Issues
0
Last Commit
1 year ago
License
MIT

Open Source Agenda Badge

Open Source Agenda Rating