ping / instagram_private_api

A Python library to access Instagram's private API.
MIT License
2.99k stars 618 forks source link

Add Story Sticker Support #166

Open Luc1412 opened 5 years ago

Luc1412 commented 5 years ago

Please follow the guide below


Before submitting an issue, make sure you have:

Which client are you using?


Describe your Feature Request:

It would be nice to add Support for Story Stickers including Link, Location, Mention, Hashtag, Polls, Music, Question, Countdowns, Vote Slider, Other Image Embeds and the new Quiz Sticker.

I already found a way by looking into the PHP API. To implement theses Stickers, we easily need to add Stuff to the Story Configuration Payload. Here is the metadata for stories:

Location:

metadata = {
    // (optional) To add a location, do BOTH of these:
    'location_sticker': [
        'width': 0.89333333333333331,
        'height': 0.071281859070464776,
        'x': 0.5,
        'y': 0.2,
        'rotation': 0.0,
        'is_sticker': true,
        'location_id': LocationObjextID?,
    ],
    'location':  LocationObject?,
}

payload['story_locations'] = json.dumps(metadata['location_sticker'])
payload['mas_opt_in'] = 'NOT_PROMPTED'

Mention:

metadata = {
    'caption': '@test',
    'story_mentions': [
        {
            'story_mentions': 'test',  # Tag WITHOUT the '@'! NOTE: This Tag MUST appear in the caption.
            'x': 0.5,  # Range: 0.0 - 1.0. Note that x = 0.5 and y = 0.5 is center of screen.
            'y': 0.5,  # Also note that X/Y is setting the position of the CENTER of the clickable area.
            'width': 0.5,  # Clickable area size, as percentage of image size: 0.0 - 1.0
            'height': 0.5,  # ...
            'rotation': 0.0,
            'is_sticker': False,  # Don't change this value.
            'use_custom_title': False  # Don't change this value.
        }
    ],
    # ... further Mentions
}
# !!! Not Checked if it works !!!
payload['reel_mentions'] = json.dumps(metadata['story_mentions'])
payload['caption'] = metadata['caption'].replace(' ', '+')
payload['mas_opt_in'] = 'NOT_PROMPTED'

Hashtag:

{
    'caption': '#test',
    'hashtags': [
        {
            'tag_name': 'test',  # Hashtag WITHOUT the '#'! NOTE: This hashtag MUST appear in the caption.
            'x': 0.5,  # Range: 0.0 - 1.0. Note that x = 0.5 and y = 0.5 is center of screen.
            'y': 0.5,  # Also note that X/Y is setting the position of the CENTER of the clickable area.
            'width': 0.5,  # Clickable area size, as percentage of image size: 0.0 - 1.0
            'height': 0.5,  # ...
            'rotation': 0.0,
            'is_sticker': False,  # Don't change this value.
            'use_custom_title': False  # Don't change this value.
        }
    ],
    # ... further hashtags
}

payload['story_hashtags'] = json.dumps(metadata['hashtags'])
payload['caption'] = metadata['caption']
payload['mas_opt_in'] = 'NOT_PROMPTED'

Polls:

{
    'story_polls': [
        {
            'question': 'example Question?',  # Story poll question. You need to manually to draw it on top of your image.
            'viewer_vote': 0,  # Don't change this value.
            'viewer_can_vote': True,  # Don't change this value.
            'tallies': [
                {
                    'text': 'Answer 1',  # Answer 1
                    'count': 0,  # Don't change this value.
                    'font_size': 35.0,  # Range: 17.5 - 35.0.
                },
                {
                    'text': "Answer 2",  # Answer 2
                    'count': 0,  # Don't change this value.
                    'font_size': 35.0,  # Range: 17.5 - 35.0.
                }
            ],
            'x': 0.5,  # Range: 0.0 - 1.0. Note that x = 0.5 and y = 0.5 is center of screen.
            'y': 0.5,  # Also note that X/Y is setting the position of the CENTER of the clickable area.
            'width': 0.24305555,  # Clickable area size, as percentage of image size: 0.0 - 1.0
            'height': 0.07347973,  # ...
            'rotation': 0.0,
            'is_sticker': True,  # Don't change this value.
        }
    ]
}

payload['story_polls'] = json.dumps(metadata['story_polls'])
payload['internal_features'] = metadata['polling_sticker']
payload['mas_opt_in'] = 'NOT_PROMPTED'

Music: ?

Questions:

{
    'story_questions': [
        # Note that you can only do one story question in this array.
        {
            'x': 0.5,  # Range: 0.0 - 1.0. Note that x = 0.5 and y = 0.5 is center of screen.
            'y': 0.5,  # Also note that X/Y is setting the position of the CENTER of the clickable area.
            'z': 0,  # Don't change this value.
            'width': 0.63118356,  # Clickable area size, as percentage of image size: 0.0 - 1.0
            'height': 0.22212838,  # ...
            'rotation': 0.0,
            'viewer_can_interact': False,  # Don't change this value.
            'background_color': '#ffffff',
            'profile_pic_url': 'https://OfficalProfilPicUrl.com',  # // Must be the profile pic url of the account you are posting from!
            'question_type': 'text',  # Don't change this value.
            'question': 'Example Question?',  # Story question.
            'text_color': '#000000',
            'is_sticker': True,  # Don't change this value.
        }
    ]
}

payload['story_questions'] = json.dumps(metadata['story_questions'])
payload['story_sticker_ids'] = 'question_sticker_ama'

Countdown:

{
    'story_countdowns': [
        {
            'x': 0.5,  # Range: 0.0 - 1.0. Note that x = 0.5 and y = 0.5 is center of screen.
            'y': 0.5,  # Also note that X/Y is setting the position of the CENTER of the clickable area.
            'z': 0,  # Don't change this value.
            'width': 0.8,  # Clickable area size, as percentage of image size: 0.0 - 1.0
            'height': 0.05,  # ...
            'rotation': 0.0,
            'text': 'Countdown Title',
            'text_color': '#ffffff',
            'start_background_color': '#ca2ee1',
            'end_background_color': '#5eb1ff',
            'digit_color': '#ffffff',
            'digit_card_color': '#1e272e',
            'end_ts': (datetime.datetime.today() + timedelta(1)).replace(hour=2, minute=0, second=0).timestamp(),  # UNIX Epoch of when the countdown expires.
            'following_enabled': True,  # If true, viewers can subscribe to a notification when the countdown expires.
            'is_sticker': True,  # Don't change this value.
        }
    ]
}

payload['story_countdowns'] = json.dumps(metadata['story_countdowns'])
payload['story_sticker_ids'] = 'countdown_sticker_time'

Vote Slider:

{
    'story_sliders': [
        {
            'question': 'example Question?',  # Story poll question. You need to manually to draw it on top of your image.
            'viewer_vote': 0,  # Don't change this value.
            'viewer_can_vote': False,  # Don't change this value.
            'slider_vote_count': 0,  # Don't change this value.
            'slider_vote_average': 0,  # Don't change this value.
            'background_color': '#ffffff',
            'text_color': '#000000',
            'emoji': '🔥',
            'x': 0.5,  # Range: 0.0 - 1.0. Note that x = 0.5 and y = 0.5 is center of screen.
            'y': 0.5,  # Also note that X/Y is setting the position of the CENTER of the clickable area.
           'width': 0.8,  # Clickable area size, as percentage of image size: 0.0 - 1.0
            'height': 0.2,  # ...
            'rotation': 0.0,
            'is_sticker': True,  # Don't change this value.
        }
    ]
}

payload['story_sliders'] = json.dumps(metadata['story_sliders'])
payload['story_sticker_ids'] = 'emoji_slider_' + metadata['story_sliders'][0]['emoji']

Image Embed:

metadata = {
    'attached_media': [
        ?
    ]
}

payload['attached_media'] = json.dumps(metadata['attached_media'])
payload['story_sticker_ids'] = ''media_simple_' + ? # Media ID?

Quiz: ?

Links: (Business only)

metadata = {
    'link': 'https://myAwsomeWebsite.de'
}

story_cta = '[{"links":[{"linkType": 1, "webUri": {0}, "androidClass": "", "package": "", "deeplinkUri": "", "callToActionTitle": "", "redirectUri": null, "leadGenFormId": "", "igUserId": "", "appInstallObjectiveInvalidationBehavior": null}]}]'.format(json.dumps(metadata['link']))
payload['story_cta'] = story_cta

Sources: https://github.com/mgp25/Instagram-API/blob/master/src/Request/Internal.php https://github.com/mgp25/Instagram-API/blob/master/examples/uploadStory.php https://github.com/mgp25/Instagram-API/blob/master/examples/uploadStoryCountdown.php https://github.com/mgp25/Instagram-API/blob/master/examples/uploadStoryPoll.php https://github.com/mgp25/Instagram-API/blob/master/examples/uploadStoryQuestion.php https://github.com/mgp25/Instagram-API/blob/master/examples/uploadStorySlider.php

eduardoegos commented 5 years ago

that would be really nice

ghost commented 5 years ago

I am going to begin working on this, if you'd like to join me.

kingmeers commented 5 years ago

Any update on this?

adarshsrivastava11 commented 4 years ago

Hi, has there been any update on this?

hgrias commented 2 years ago

Has anyone found a way to get Music metadata associated with a story?