All Projects → deni2312 → InstagramAPI

deni2312 / InstagramAPI

Licence: MIT license
C++17 header only Instagram API

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to InstagramAPI

instagramBot
A NodeJS wrapper for the Instagram Bot It works with instagram private api ,It has almost all the features the Instagram app.
Stars: ✭ 40 (+11.11%)
Mutual labels:  instagramapi

C++ Instagram API

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

Getting started.

Steps

This API is tested with C++ 17, on linux g++.

Linux

Install on linux with vcpkg:

  • Dependencies
    • nlohmann-json
    • cpr
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 a 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.

Contacts

You can contact us on Telegram for any issue or doubt.
@deni2312

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].