Giter Site home page Giter Site logo

subzeroid / instagrapi-rest Goto Github PK

View Code? Open in Web Editor NEW
432.0 10.0 118.0 129 KB

RESTful API Wrapper for Instagram Private API

Home Page: https://hikerapi.com/p/ygXxF38v

License: MIT License

Dockerfile 0.60% Python 84.77% Go 12.50% Swift 2.04% Procfile 0.10%
instagram instagram-api instagram-bot instagram-scraper instagram-downloader instagram-photos instagram-client instagram-feed instagram-stories instagram-sdk

instagrapi-rest's People

Contributors

adw0rd avatar bedefaced avatar cyrus07424 avatar erezamihud avatar franciscodadone avatar gholamrezaeipt avatar jmallone avatar nathanfallet avatar orthlus avatar soneji avatar stiveknx avatar subzeroid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

instagrapi-rest's Issues

/photo/upload endpoint not working

curl -X 'POST' \
  'https://api.website.com/photo/upload' \
  -H 'accept: application/json' \
  -H 'Content-Type: multipart/form-data' \
  -F 'sessionid=XYZ' \ #session id works
  -F '[email protected];type=image/jpeg' \
  -F 'caption=cap'

Error: response status is 500

{
  "detail": "{\"message\":\"login_required\",\"status\":\"fail\"}",
  "exc_type": "PhotoNotUpload"
}

compose logs are:

api_1  | INFO:     None [403] POST https://i.instagram.com/rupload_igphoto/1631650226816_0_1319177777 (203.0.0.29.118, Xiaomi capricorn)
api_1  | ERROR:    Photo Upload failed with the following response: <Response [403]>
api_1  | INFO:     172.28.0.1:44202 - "POST /photo/upload HTTP/1.1" 500 Internal Server Error
api_1  | ERROR:    Exception in ASGI application
api_1  | Traceback (most recent call last):
api_1  |   File "/usr/local/lib/python3.8/site-packages/uvicorn/protocols/http/httptools_impl.py", line 385, in run_asgi
api_1  |     result = await app(self.scope, self.receive, self.send)
api_1  |   File "/usr/local/lib/python3.8/site-packages/uvicorn/middleware/proxy_headers.py", line 45, in __call__
api_1  |     return await self.app(scope, receive, send)
api_1  |   File "/usr/local/lib/python3.8/site-packages/fastapi/applications.py", line 199, in __call__
api_1  |     await super().__call__(scope, receive, send)
api_1  |   File "/usr/local/lib/python3.8/site-packages/starlette/applications.py", line 112, in __call__
api_1  |     await self.middleware_stack(scope, receive, send)
api_1  |   File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 181, in __call__
api_1  |     raise exc from None
api_1  |   File "/usr/local/lib/python3.8/site-packages/starlette/middleware/errors.py", line 159, in __call__
api_1  |     await self.app(scope, receive, _send)
api_1  |   File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 82, in __call__
api_1  |     raise exc from None
api_1  |   File "/usr/local/lib/python3.8/site-packages/starlette/exceptions.py", line 71, in __call__
api_1  |     await self.app(scope, receive, sender)
api_1  |   File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 580, in __call__
api_1  |     await route.handle(scope, receive, send)
api_1  |   File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 241, in handle
api_1  |     await self.app(scope, receive, send)
api_1  |   File "/usr/local/lib/python3.8/site-packages/starlette/routing.py", line 52, in app
api_1  |     response = await func(request)
api_1  |   File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 201, in app
api_1  |     raw_response = await run_endpoint_function(
api_1  |   File "/usr/local/lib/python3.8/site-packages/fastapi/routing.py", line 148, in run_endpoint_function
api_1  |     return await dependant.call(**values)
api_1  |   File "/app/./routers/photo.py", line 138, in photo_upload
api_1  |     return await photo_upload_post(
api_1  |   File "/app/./helpers.py", line 33, in photo_upload_post
api_1  |     return cl.photo_upload(fp.name, **kwargs)
api_1  |   File "/usr/local/lib/python3.8/site-packages/instagrapi/mixins/photo.py", line 208, in photo_upload
api_1  |     upload_id, width, height = self.photo_rupload(path, upload_id)
api_1  |   File "/usr/local/lib/python3.8/site-packages/instagrapi/mixins/photo.py", line 170, in photo_rupload
api_1  |     raise PhotoNotUpload(response.text, response=response, **last_json)
api_1  | instagrapi.exceptions.PhotoNotUpload: {"message":"login_required","status":"fail"}

It says login required but my token works on the /auth/timeline_feed endpoint

[BUG] Download by url

Describe the bug
A clear and concise description of what the bug is.
download by url function doesnt work, i get an index out of range error , and when i try to "fix" it by rewriting how it saves the name of the downloaded file , i get a

Content-length=28682, but file length=9785

error

To Reproduce
Provide a piece of code to reproduce the problem.
run /video/download/by_url/

Traceback
Show your full traceback so that it is clear where exactly the error occurred.

/instagrapi-rest-main/instagrapi-rest-main/.venv/lib/python3.9/site-packages/instagrapi/mixins/video.py", line 85, in video_download_by_url
    filename = "%s.%s" % (filename, fname.rsplit(".", 1)[1]) if filename else fname
IndexError: list index out of range

Expected behavior
A clear and concise description of what you expected to happen.
download a video

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: [e.g. Ubuntu 21.04]
  • Python version [e.g. 3.8.3]
  • instagrapi version [e.g. 1.9.3, not "latest"]
  • moveipy version if used
  • imagemagick version if used

Additional context
Add any other context about the problem here.
Screenshot 2022-05-01 at 7 23 56 PM

Screenshot 2022-05-01 at 7 23 19 PM

Share session id across devices

I haven't read the complete code yet but wanted to know if its possible to store and share the session to diferent devices instead of having to login every single time, I ask this because as I was trying to set it up as a service on AWS and I almost got my account locked out

[BUG] status code 500 while trying to login

http://localhost:8000/auth/login
I am trying to login. Account has 2FA . First I filled username and password after that I get the 2FA code via email and filled the input and send another request but still getting 500 error.
I am using the docker environment.
image
shown in the above picture Is mock data. However, I have tried with the real account but, it did not work either.

see below:
image

[BUG]

Describe the bug

I ran the docker image and I only see 2 options in the API

image

To Reproduce

I ran the docker image by docker run -p 8000:8000 adw0rd/instagrapi-rest

Desktop (please complete the following information):

  • OS: Windows 10

[BUG] Raspberry Pi/Arm support

I would like to run this API on my pi, but have been unable to do so because the image this API is based on, only runs on x86.

I have managed to get it running on my pi by modifying the Dockerfile a little and copying a few (around 5) files from the https://github.com/tiangolo/uvicorn-gunicorn-docker project.

This would also reduce the project's dependance on external Docker images. Dependance could be bad if the owners disappear.

If this is something you'd be willing to support, let me know and I can make a PR.

diff --git a/Dockerfile b/Dockerfile
index 3f0cad6..1231591 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,5 +1,34 @@
-FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8-slim
+# gunicorn image
+FROM python:3.8-slim as my_gunicorn

+RUN apt-get update \
+&& apt-get install gcc ffmpeg -y \
+&& apt-get clean
+
+RUN pip install --no-cache-dir "uvicorn[standard]" gunicorn
+
+COPY uvicorn-gunicorn-docker/docker-images/start.sh /start.sh
+RUN chmod +x /start.sh
+
+COPY uvicorn-gunicorn-docker/docker-images/gunicorn_conf.py /gunicorn_conf.py
+
+COPY uvicorn-gunicorn-docker/docker-images/start-reload.sh /start-reload.sh
+RUN chmod +x /start-reload.sh
+
+COPY uvicorn-gunicorn-docker/docker-images/app /app
+WORKDIR /app/
+
+ENV PYTHONPATH=/app
+
+EXPOSE 80
+
+# Run the start script, it will check for an /app/prestart.sh script (e.g. for migrations)
+# And then will start Gunicorn with Uvicorn
+CMD ["uvicorn-gunicorn-docker/docker-images/start.sh"]
+
+
+#FROM tiangolo/uvicorn-gunicorn-fastapi:python3.8-slim
+FROM my_gunicorn
 # RUN apt-get update \
 #     && apt-get install --yes --no-install-recommends \
 #         build-essential python-dev
@@ -13,4 +42,5 @@ COPY . /app/
 WORKDIR /app
 RUN pip install -r requirements.txt

-CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
\ No newline at end of file
+CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000", "--reload"]
+

Adding features

I suggest that you should add more features like

  • The "Insight" feature from the instagrapi
  • The friendship status of user with list user following (isBestie, isFollowingYou, v.v)
  • The rest api to know if someone unfollow user himself?

/media/pk_from_url not working

Python console

>>> Client().media_pk_from_url("https://www.instagram.com/p/CTZRfJEDsE7/")
2655230362137837883

API request:
image

API logs:

api_1  | https://www.instagram.com/p/CTZRfJEDsE7/
api_1  | INFO:     172.28.0.1:39612 - "GET /media/pk_from_url?url=https%3A%2F%2Fwww.instagram.com%2Fp%2FCTZRfJEDsE7%2F HTTP/1.1" 200 OK

I added in a print to see the URL is correct... not sure why it's not working, and appears to be adding extra zeroes
image

[BUG]

"detail": "The username you entered doesn't appear to belong to an account. Please check your username and try again.",
"exc_type": "UnknownError"

[BUG] Invalid parameters

Describe the bug
Getting invalid parameters when trying to login using 2FA.

To Reproduce
curl -X 'GET'
'http://localhost:8000/auth/login'
-H 'accept: application/json'
-H 'Content-Type: application/x-www-form-urlencoded'
-d 'username=&password=&verification_code=<2FA CODE>'

Traceback
{
"detail": "Invalid Parameters",
"exc_type": "UnknownError"
}

Expected behavior
Get sessionid.

Additional context
Using docker container.

Pagination of /media/user_medias

Try Instagrapi SaaS with a free trial https://hikerapi.com/p/5GBWznd3

Is your feature request related to a problem? Please describe.
Then /media/user_medias route only returns the last e.g. 50 medias, and there is no way of telling it "get the 50 medias before the 50 you fetched last time" - or in other words: paginate ;-)

Describe the solution you'd like
I'd like to have the pagination that instagrapi provides also implemented in instagrapi-rest. :-)

Describe alternatives you've considered
Not using instagrapi-rest... which would be a shame, because quick testing shows that it's working really nicely!

[BUG] Getting 'Unprocessable Entity'

Describe the bug
I get Unprocessable Entity when passing usertags to upload a clip. (From NodeJS)

To Reproduce

const FormData = require('form-data');

const formData = new FormData();
formData.append('sessionid', sessionid);
  formData.append('caption', caption);
  formData.append('url', url);
  formData.append(
    'usertags',
    `{"user": {"pk": "${userInfo.pk}", "username": "${userInfo.username}", "full_name": "${userInfo.full_name}", "profile_pic_url": "${userInfo.profile_pic_url}", "profile_pic_url_hd": "${userInfo.profile_pic_url_hd}", "stories": []}, "x": 0, "y": 0}`
  );

fetch(`${process.env.INSTAGRAPI_URL}/clip/upload/by_url`, {
    method: 'POST',
    headers: formData.getHeaders(),
    body: formData,
  })

Traceback
rcplanesglobalbot-webversion-instagrapi-1 | INFO: 172.23.0.3:44116 - "POST /clip/upload/by_url HTTP/1.1" 422 Unprocessable Entity

Expected behavior
Upload the clip with the user tagged in it.

Desktop (please complete the following information):

  • OS: Fedora 34
  • Python version 3.8-slim
  • instagrapi version 1.0.0 (as localhost:8000 says)

Additional context
If I remove

 formData.append(
    'usertags',
    `{"user": {"pk": "${userInfo.pk}", "username": "${userInfo.username}", "full_name": "${userInfo.full_name}", "profile_pic_url": "${userInfo.profile_pic_url}", "profile_pic_url_hd": "${userInfo.profile_pic_url_hd}", "stories": []}, "x": 0, "y": 0}`
  );

the clip uploads correctly but when I add the 'usertags' it gives me that error.

Proper way to handle checkpoints on instagrapi-rest

While using instagrapi-rest, is useless to use the default behavior for instagrapi, to ask the SMS / E-mail code on input (STDIN).
https://github.com/adw0rd/instagrapi/blob/092b19713f920e13641c45899be5f3afab827cf4/instagrapi/mixins/private.py#L33

Since we run on an server, which is probably runing on a background task, there's no interaction with it.

A simple fork would be just setting a new challenge_code_handler
Stiveknx@90a2b23#diff-edcfd80d7c5e51c05a01f8fc4079088fe44e05a58382b801009203aca3c8ff3dR27

But, it should be possible to "resume" the previous one challenge.
The "resume", would just send a post to challenge url with the code.
It could be an endpoint, like this one:
Stiveknx@90a2b23#diff-edcfd80d7c5e51c05a01f8fc4079088fe44e05a58382b801009203aca3c8ff3dR65

But, I didn't find out, how to resume an Checkpoint, or specifically, how to "save" previous checkpoint data and resume it after.

Any clues?

About requests to the rest api

First of all thanks for creating such a solid framework. I am kind of new to these concepts so sorry if that's a silly question. Say I deployed this repo to a google cloud service and base url for the api is now the service's url. Further, there are requests made to that url from multiple sources with different ip addresses. In that case, source of the traffic to instagram is the ip address of the virtual machine that deployed service runs on or ip addresses where requests come from?

Bug in Upload Foto do Story

Hi, how are you?

I encountered a problem when uploading a photo via the API. I'm getting the Token correctly. But when filling in the data... It presents the following error:

{
   "detail": "must be real number, not NoneType",
   "exc_type": "TypeError"
}

image

7c6377c2-95c2-4a89-aa9e-2729a7950de0

add method

how can i add method like cl.media_comments(media_id)
thanks

Idea: change the API so that it remembers the session id, we don't have to provide it each time

Hi

I am trying to make an app using this incredible tool, however I feel some of the logic could be streamlined if the internal state of the REST API allowed for saving the session id, or at least having a mode for this. I would like to be able to:

  • login (once)
  • send request to make an instagram post with just the account username (can be many times across many days)
    • if there is an existing session, use that token to make the post
    • if there is not an existing session, return error
      • user can handle the error by sending the login request again, and then the instagram post request

The benefit of something like this is that I don't have to worry about storing any session id, which could change/become invalid at any time, within my application. I just need to store my IG user/pass, which can be used if and when the session id becomes invalid.

I feel like this could be quite easily achieved using the library "load_settings" and "dump_settings" and stored in a particular location, such as /etc/instagrapi-rest/user1.json, user2.json...

Then for Docker users (like myself), we can map that folder to a volume, ensuring that the state is maintained across container restarts. This also provides the benefit that the "device" info is maintained across container restarts too, so "Instagram can trust you more".

how to setup in windows 10

I am new to python and I really don't know how to setup this API project in windows.
Could you provide doc or detail info. for setup this project in windows?

Hashtag media recent like in python?

I wonder if there's a way to get recent media by hashtag similar to the way in python:
medias = cl.hashtag_medias_recent('airplane', amount=400) ?

Thank you

[BUG] Adding mentions returns 422

Describe the bug
Whenever I send

[
    {
        'user': { 'pk': 'PK' }
    }
]

As mentions on the /video/upload_to_story/by_url it returns a 422 stating that {'detail': [{'loc': ['body', 'mentions', 0], 'msg': 'value is not a valid dict', 'type': 'type_error.dict'}]}

When infact it's a dict, I've even checked the SRC to verify if my data is correct and it seems like its 100% correct, even the OpenAPI doc has an error when I fill it out.

To Reproduce
Try using mentions on the OpenAPI spec, it'll return a 422

Desktop (please complete the following information):

  • OS: [e.g. Ubuntu 21.04]
  • Python version [e.g. 3.8.3] 3.9.7
  • instagrapi version [e.g. 1.9.3, not "latest"] OpenAPI shows its 1.0.0 but unsure, downloaded the repo a couple days ago
  • moveipy version if used
  • imagemagick version if used

How can i get sessionId after login

After login successfully, how can I obtain the sessionId to test other API requests?

curl -X 'POST' \
  'http://192.168.1.250/auth/login' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'username=XXXX&password=XXXXX&verification_code=&proxy=&locale=&timezone='

[BUG] Don't build in docker

I try run command
docker-compose buld
or
docker build -t instagrapi-rest .

I get an error at the stage of installing dependencies (RUN pip install -r requirements.txt)


Collecting tqdm<5.0,>=4.11.2
  Downloading tqdm-4.62.2-py2.py3-none-any.whl (76 kB)
INFO: This is taking longer than usual. You might need to provide the dependency resolver with stricter constraints to reduce runtime. If you want to abort this run, you can press Ctrl + C to do so. To improve how pip performs, tell us what happened here: https://pip.pypa.io/surveys/backtracking
  Downloading tqdm-4.62.1-py2.py3-none-any.whl (76 kB)
  Downloading tqdm-4.62.0-py2.py3-none-any.whl (76 kB)
  Downloading tqdm-4.61.2-py2.py3-none-any.whl (76 kB)
  Downloading tqdm-4.61.1-py2.py3-none-any.whl (75 kB)
  Downloading tqdm-4.61.0-py2.py3-none-any.whl (75 kB)
ERROR: Exception:
Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/pip/_internal/cli/base_command.py", line 173, in _main
    status = self.run(options, args)
  File "/usr/local/lib/python3.8/site-packages/pip/_internal/cli/req_command.py", line 203, in wrapper
    return func(self, options, args)
  File "/usr/local/lib/python3.8/site-packages/pip/_internal/commands/install.py", line 315, in run
    requirement_set = resolver.resolve(
  File "/usr/local/lib/python3.8/site-packages/pip/_internal/resolution/resolvelib/resolver.py", line 94, in resolve
    result = self._result = resolver.resolve(
  File "/usr/local/lib/python3.8/site-packages/pip/_vendor/resolvelib/resolvers.py", line 472, in resolve
    state = resolution.resolve(requirements, max_rounds=max_rounds)
  File "/usr/local/lib/python3.8/site-packages/pip/_vendor/resolvelib/resolvers.py", line 383, in resolve
    raise ResolutionTooDeep(max_rounds)
pip._vendor.resolvelib.resolvers.ResolutionTooDeep: 2000000
The command '/bin/sh -c pip install -r requirements.txt' returned a non-zero code: 2

[BUG] Auth login error

Good day sir , im having issues tyring to login via /auth/login with golang and the error also occurs when using the instagrapi interface
Screenshot 2021-10-19 at 11 40 35 AM

Screenshot 2021-10-19 at 10 42 30 AM

Screenshot 2021-10-19 at 10 42 55 AM

Screenshot 2021-10-19 at 10 42 21 AM

func Login(username, password string) string { resp, err := Client.R(). SetFormData(map[string]string{ "username": username, "password": password, }).Post("/auth/login") if err != nil { log.Println(err) } if resp.StatusCode() != 200 { log.Println(errors.ErrLoginFailed) } if resp.StatusCode() == 422 { log.Println(errors.ErrIncorrectDetails) } return fmt.Sprintf("Login Sucessful into %s", username) }

set proxy to all api

Hi
how can i set proxy and timezone and every extra headers to every api ?
tnx

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.