示例#1
0
    def getTopMediaWithHashtag(self, hashtag_id, user_id, data_fields=None):
        """
        Represents a collection of the most recently published photo and video IG Media objects that have been tagged with a hashtag.

        Query String Parameters:
            {user_id} (required) — The ID of the IG User performing the query.
            {fields} — A comma-separated list of fields you want returned. See Returnable Fields.
        Limitations
            Only returns public photos and videos.
            Only returns media objects published within 24 hours of query execution.
            Will not return promoted/boosted/ads media.
            Responses are paginated with a maximum limit of 50 results per page.
            Responses will not always be in chronological order.
            You can query a maximum of 30 unique hashtags within a 7 day period.
            You cannot request the username field on returned media objects.
            Responses will not include any personally identifiable information.
            This endpoint only returns an after cursor for paginated results; a before cursor will not be included. In addition, the after cursor value will always be the same for each page, but it can still be used to get the next page of results in the result set.
        """
        if not data_fields:
            data_fields = "{caption,children,comments_count,id,like_count,media_type,media_url, permalink,timestamp,}"

        params = {
            'fields': data_fields,
            'user_id': user_id,
            'access_token': self.user_access_token
        }

        url = self.url + hashtag_id + '/top_media'

        return makeGetApiCall(url, params, debug=self.debug)
示例#2
0
    def findUserFollowing(self,
                          id,
                          max_results=None,
                          pagination_token=None,
                          expansions=None,
                          tweet_fields=None,
                          user_fields=None):
        """ Returns a list of users the specified user ID is following."""
        if max_results:
            params.update({'max_results': max_results})
        if pagination_token:
            params.update({'pagination_token': pagination_token})
        if expansions:
            params.update({'expansions': expansions})
        if tweet_fields:
            params.update({'tweet_fields': tweet_fields})
        if user_fields:
            params.update({'user_fields': user_fields})

        url = self.base_url + f'/users/{id}/following'

        return makeGetApiCall(url,
                              params=params,
                              header=self.header,
                              debug=self.debug)
示例#3
0
    def getIGUserMetadata(self, username):
        params = {
            'fields': 'business_discovery.username(' + username + ')'
            'access_token': self.user_access_token
        }

        url = self.url + self.instagram_account_id
        return makeGetApiCall(url, params, debug=self.debug)
示例#4
0
    def findRecentlySearchedHashtags(self):
        """
        Get the IG Hashtags that an IG User has searched for within the last 7 days. You can query a maximum of 30 unique hashtags on behalf of a user within a rolling, 7 day period. A queried hashtag will count against that user's limit as soon as it is queried. Subsequent queries on that hashtag within 7 days of the initial query will not count against the user's limit.

        Limitations
            Emojis in hashtag queries are not supported.
            The API returns 25 results per page by default, but you can use the limit parameter to get up to 30 per page (limit=30).
        """
        url = self.url + self.instagram_account_id + '/' + 'recently_searched_hashtags'
        return makeGetApiCall(url, params, debug=self.debug)
示例#5
0
    def readMentionedInMedia(self, media_id, data_fields=None):
        if not data_fields:
            data_fields = '{caption,comments,comment_count,id,like_count,media_type,media_url,owner,timestamp,username}'

        params = {
            'fields': 'mentioned_media.media_id(' + media_id + ')' + data_fields
            'access_token': self.user_access_token
        }

        url = self.url + self.instagram_account_id
        return makeGetApiCall(url, params, debug=self.debug)
示例#6
0
    def getIGUserMedia(self, username, data_fields=None):
        if not data_fields:
            data_fields = "{biography,id,ig_id,followers_count,follows_count,media_count,name,profile_picture_url,username,website}"

        params = {
            'fields': 'business_discovery.username(' + username + ')' + data_fields
            'access_token': self.user_access_token
        }

        url = self.url + self.instagram_account_id
        return makeGetApiCall(url, params, debug=self.debug)
示例#7
0
    def getUserStories(self, data_fields=None):
        """ Returns a list of story IG Media objects on an IG User. """
        if not data_fields:
            data_fields = '{comments_count,caption,id,is_comment_enabled,ig_id,media_type,media_url,permalink,owner,like_count,thumbnail_url,shortcode,username}'

        params = {
            'fields': data_fields,
            'access_token': self.user_access_token
        }

        url = self.url + self.instagram_account_id + '/stories'
        return makeGetApiCall(url, params, debug=self.debug)
示例#8
0
    def connectStream(self,
                      expansions=None,
                      tweet_fields=None,
                      media_fields=None,
                      place_fields=None,
                      poll_fields=None,
                      user_fields=None):
        """Streams Tweets in real-time based on a specific set of filter rules. """

        url = self.base_url + '/tweets/search/stream'

        return makeGetApiCall(url, headers=self.headers, debug=self.debug)
示例#9
0
    def getSingleUserData(self, id, expansions=None, tweet_fields=None, user_fields=None):
        """ Returns a variety of information about one or more users specified by the ID. """
        url = self.base_url + f'/users/{id}'

        if expansions:
            params.update({'expansions':expansions})
        if tweet_fields:
            params.update({'tweet_fields':tweet_fields})
        if user_fields:
            params.update({'user_fields': user_fields})

        return makeGetApiCall(url, params=params, header=self.header, debug=self.debug)
示例#10
0
    def getUserTags(self, data_fields=None):
        """ Returns a list of IG Media objects in which an IG User has been tagged by another Instagram user. """
        if not data_fields:
            data_fields='{caption,comments,comments_count,id,like_count,media_type,media_url,owner,timestamp,username}'

        params = {
            'fields': data_fields,
            'access_token': self.user_access_token
        }

        url = self.url + self.instagram_account_id + '/tags'
        return makeGetApiCall(url, params, debug=self.debug)
示例#11
0
    def getUserInsights(self, metric, period, since=None, until=None, data_fields=None, limit=10):
        """
        List of metrics and periods: https://developers.facebook.com/docs/instagram-api/reference/user/insights

        since/until are Unix timestamps.
        """
        if ref == 'media':
            if not data_fields:
                data_fields= '{description,id,name,period,title,values}'

        if ref == 'hashtag'

        metric

        params = {
            'fields': data_fields,
            'metric': metric,
            'period': period,
            'limit': limit,
            'access_token': self.user_access_token
        }

        if since and update:
            params.update({'since': since, 'update':update})

        url = self.url + self.instagram_account_id + '/insights'
        return makeGetApiCall(url, params, debug=self.debug)

    def getUserStories(self, data_fields=None):
        """ Returns a list of story IG Media objects on an IG User. """
        if not data_fields:
            data_fields = '{comments_count,caption,id,is_comment_enabled,ig_id,media_type,media_url,permalink,owner,like_count,thumbnail_url,shortcode,username}'

        params = {
            'fields': data_fields,
            'access_token': self.user_access_token
        }

        url = self.url + self.instagram_account_id + '/stories'
        return makeGetApiCall(url, params, debug=self.debug)

    def getUserTags(self, data_fields=None):
        """ Returns a list of IG Media objects in which an IG User has been tagged by another Instagram user. """
        if not data_fields:
            data_fields='{caption,comments,comments_count,id,like_count,media_type,media_url,owner,timestamp,username}'

        params = {
            'fields': data_fields,
            'access_token': self.user_access_token
        }

        url = self.url + self.instagram_account_id + '/tags'
        return makeGetApiCall(url, params, debug=self.debug)
示例#12
0
    def retrieveRules(self, ids):
        """
        Return a list of rules currently active on the streaming endpoint, either as a list or individually.
        """
        url = self.base_url + '/tweets/search/stream/rules'
        params = {}
        if ids:
            params.update({'ids': ids})

        return makeGetApiCall(url,
                              params=params,
                              headers=self.headers,
                              debug=self.debug)
示例#13
0
    def getHashtag(self, hashtag_id, data_fields=None):
        """ Returns Fields and Edges on an IG Hashtag."""
        if not data_fields:
            data_fields = "{id,name}"

        params = {
            'fields': data_fields,
            'access_token': self.user_access_token
        }

        url = self.url + hashtag_id

        return makeGetApiCall(url, params, debug=self.debug)
示例#14
0
    def getMultipleUserData(self, ids, expansions=None, tweet_fields=None, user_fields=None):
        """ Returns a variety of information about one or more users specified by the requested IDs. """

        url = self.base_url + '/users'
        params = {'ids': ids}

        if expansions:
            params.update({'expansions':expansions})
        if tweet_fields:
            params.update({'tweet_fields':tweet_fields})
        if user_fields:
            params.update({'user_fields': user_fields})

        return makeGetApiCall(url, params=params, header=self.header, debug=self.debug)
示例#15
0
    def getPageId(self, page_name, user_id, access_token, debug=True):
        """
        Grab Page Id from page_name, user_id and access token.
        GET https://graph.facebook.com/v9.0/10223398117842352/accounts?access_token=EAAC8CYgeaz8BAL5RWRQxNuhaIuaYp0PXMxq1G0e4Hm7sgA7ugw5c2L6zxTkMX5AFrdRuHVKFMcmAC17TqJ5JzSs81NJ5oDwaPGsh4oQ2YmVxWbjt7AJIjT4AVF4tnGyf5UxJGJnIy4k9aVmu5utuoQXxg2biwkViXjT8aAZDZD
        """

        params = setRequestParams()
        url = self.url + user_id + "/accounts?"
        response = makeGetApiCall(url, params, debug)

        for data in response['data']:
            if data.get('name') == page_name:
                return data.get('id')
        return ''
示例#16
0
    def getMentionTimelineByID(self,
                               id,
                               expansions=None,
                               tweet_fields=None,
                               media_fields=None,
                               place_fields=None,
                               poll_fields=None,
                               user_fields=None):
        url = self.base_url + f'/users/{id}/mentions'
        params = get_all_params({}, expansions, tweet_fields, media_fields,
                                place_fields, poll_fields, user_fields)

        return makeGetApiCall(url,
                              params=params,
                              headers=self.headers,
                              debug=self.debug)
示例#17
0
    def getMediaObjectInsights(self, media_id, metric):
        """ Get insights data on an IG Media object. Values for each metric are calculated at the time of the request.

        Limitations
            - Insights data is not available for IG Media objects within album IG Media objects.
            Story IG Media object insights are only available for 24 hours, even if the stories are archived or highlighted. If you want to get the latest insights for a story before it expires, set up a Webhook for the Instagram topic and subscribe to the story_insights field.
            - Story IG Media object metrics with values less than 5 will return an error code 10 with the message (#10) Not enough viewers for the media to show insights.

        See for metric choices:
        https://developers.facebook.com/docs/instagram-api/reference/media/insights

        """
        params = {'access_token': self.user_access_token}

        url = self.url + media_id + '/insights'
        return makeGetApiCall(url, params, debug=self.debug)
示例#18
0
 def getTweetTimelineByID(self,
                          id,
                          expansions=None,
                          tweet_fields=None,
                          media_fields=None,
                          place_fields=None,
                          poll_fields=None,
                          user_fields=None):
     """
     Returns Tweets composed by a single user, specified by the requested user ID. By default, the most recent 10 Tweets are returned per request with the default Tweet id and text. Using pagination, the most recent 3,200 Tweets can be retrieved.
     """
     url = self.base_url + f'/users/{id}/tweets'
     params = get_all_params({}, expansions, tweet_fields, media_fields,
                             place_fields, poll_fields, user_fields)
     return makeGetApiCall(url,
                           params=params,
                           headers=self.headers,
                           debug=self.debug)
示例#19
0
    def findUserFollowers(self, id):
        if max_results:
            params.update({'max_results': max_results})
        if pagination_token:
            params.update({'pagination_token': pagination_token})
        if expansions:
            params.update({'expansions': expansions})
        if tweet_fields:
            params.update({'tweet_fields': tweet_fields})
        if user_fields:
            params.update({'user_fields': user_fields})

        url = self.base_url + f'/users/{id}/following'

        return makeGetApiCall(url,
                              params=params,
                              header=self.header,
                              debug=self.debug)
示例#20
0
    def getInstagramAccountId(self, instagram_account_id, debug=True):
        """
        Grab instagram account id from page_id and access token.
        GET "https://graph.facebook.com/v9.0/{page_id}?fields=connected_instagram_account&access_token={user_token}
        """
        if instagram_account_id:
            return instagram_account_id

        params = setRequestParams(fields='connected_instagram_account')

        response = makeGetApiCall(self.url + self.page_id, params, debug)

        account = response['json_data'].get('connected_instagram_account', '')
        if "id" not in account:
            return account

        instagram_account_id = account['id']
        return instagram_account_id
示例#21
0
    def recentPublicSearch(self,
                           query,
                           since_id=None,
                           start_time=None,
                           max_results=None,
                           end_time=None,
                           next_token=None,
                           until_id=None,
                           expansions=None,
                           tweet_fields=None,
                           media_fields=None,
                           place_fields=None,
                           poll_fields=None,
                           user_fields=None):
        """
        The recent search endpoint returns Tweets from the last 7 days that match a search query.

        At our Basic access level, you will be limited to receive 500,000 Tweets per month per project from either the filtered stream or search Tweets endpoints. For example, if you consumed 200,000 Tweets with filtered stream, you will be able to receive an additional 300,000 Tweets from either filtered stream or search Tweets. Once you have used up this allotment, you will need to wait until the next monthly period begins, which is set to the day that your developer account was approved.

        """
        params = {'query': query}
        if since_id:
            params.update({'since_id': since_id})
        if start_time:
            params.update({'start_time': start_time})
        if max_results:
            params.update({'max_results': max_results})
        if end_time:
            params.update({'end_time': end_time})
        if until_id:
            params.update({'until_id': until_id})
        if next_token:
            params.update({'next_token': next_token})

        params = get_all_params(params, expansions, tweet_fields, media_fields,
                                place_fields, poll_fields, user_fields)
        url = self.base_url + '/tweets/search/recent'

        return makeGetApiCall(url,
                              params=params,
                              headers=self.headers,
                              debug=self.debug)
示例#22
0
    def getUserComments(self, media_id, data_fields=None):
        """
        Grab comments of a media object.
        Limitations:
            Fields that return aggregated values will not include ads-driven data. For example, comments_count will count comments on a photo, but not comments on ads that contain that photo.
            Captions will not include the (@) symbol unless the app user is also able to perform Admin-equivalent Tasks on the app.
            Some Fields cannot be used on Photos within Albums (children).
            The media_url field will be omitted from responses if the IG Media contains copyrighted material or has been flagged for a copyright violation.
            IGTV and Reels are not supported.
        """
        if not data_fields:
            data_fields = '{hidden,id,like_count,media,replies,text,timestamp,user,username}'

        params = {
            'fields': data_fields,
            'access_token': self.user_access_token
        }

        url = self.url + self.instagram_account_id + '/' + comment_id
        return makeGetApiCall(url, params, debug=self.debug)
示例#23
0
    def getAccountInfo(self, data_fields=None):
        """
        Get Account info:
            - username, website, name, ig_id, id, profile_picture_url, biography, follows_count, followers_count, media_count

        API Endpoint:
        https://graph.facebook.com/v9.0{user-id}?fields=business_discovery.username({username}){username,website,name,ig_id,id,profile_picture_url,biography,follows_count,followers_count,media_count}&&access_token={access_token}
        """
        if not fields:
            data_fields = '{username,website,name,ig_id,id,profile_picture_url,biography,follows_count,followers_count,media_count}'

        params = {
            'fields':
            'business_discovery.username(' + self.instagram_username + ')' +
            data_fields,
            'access_token':
            self.user_access_token
        }
        url = self.url + self.instagram_account_id
        return makeGetApiCall(url, params, debug=self.debug)
示例#24
0
    def getUserMedia(self, ref, data_fields=None, pagingUrl=''):
        """
        ref = (tags, stories, recently_searched_hashtags, media)
        API Endpoint:
            https://graph.facebook.com/{graph-api-version}/{ig-user-id}/{ref}?fields={fields}&access_token={access-token}

        Returns object: data from the endpoint
        """

        if not data_fields:
            # set default fields
            data_fields = '{id,caption,media_type,media_url,permalink,thumbnail_url,timestamp,username}'

        params = {
            'fields': data_fields,
            'access_token': self.user_access_token
        }

        url = self.url + self.instagram_account_id + '/media'
        return makeGetApiCall(url, params, debug=self.debug)
示例#25
0
    def getTweet(self,
                 id,
                 expansions=None,
                 tweet_fields=None,
                 media_fields=None,
                 place_fields=None,
                 poll_fields=None,
                 user_fields=None):
        """
        Returns a variety of information about the Tweet specified by the requested ID
        """
        url = self.base_url + '/tweets' + '/' + id
        params = {'id': id} if id else {}
        params = get_all_params(params, expansions, tweet_fields, media_fields,
                                place_fields, poll_fields, user_fields)

        return makeGetApiCall(url,
                              params=params,
                              headers=self.headers,
                              debug=self.debug)
示例#26
0
    def getTweets(self,
                  ids,
                  expansions=None,
                  tweet_fields=None,
                  media_fields=None,
                  place_fields=None,
                  poll_fields=None,
                  user_fields=None):
        """
        Returns a variety of information about the Tweet specified by the list of IDs.
        """

        url = self.base_url + '/tweets'
        params = {'ids': ids}
        params = get_all_params(params, expansions, tweet_fields, media_fields,
                                place_fields, poll_fields, user_fields)

        return makeGetApiCall(url,
                              params=params,
                              headers=self.headers,
                              debug=self.debug)
示例#27
0
    def readMentionedInComment(self, comment_id, data_fields=None):
        """
        Returns data on an IG Comment in which an IG User has been @mentioned by another Instagram user.

        Limitations
            This endpoint will return an error if comments have been disabled on the IG Media on which the IG User has been @mentioned.

        Field Expansion:
            - media

        TODO: Pagination
        """

        if not data_fields:
            data_fields = '{id,like_count,media{id,media_url},text,timestamp}'

        params = {
            'fields': 'mentioned_comment.comment_id(' + comment_id + ')' + data_fields
            'access_token': self.user_access_token
        }

        url = self.url + self.instagram_account_id
        return makeGetApiCall(url, params, debug=self.debug)
示例#28
0
    def getMediaObjectComments(self, media_id):
        """ Returns a list of IG Comments on an IG Media object. """
        params = {'access_token': self.user_access_token}

        url = self.url + media_id + '/comments'
        return makeGetApiCall(url, params, debug=self.debug)
示例#29
0
    def getChildrenMediaObjects(self, media_id):
        """ Returns a list of IG Media objects on an album IG Media object. """
        params = {'access_token': self.user_access_token}

        url = self.url + media_id + '/children'
        return makeGetApiCall(url, params, debug=self.debug)
示例#30
0
 def getAllCommentReplies(self, comment_id, data_fields):
     params = {
         'access_token': self.user_access_token
     }
     url = self.url + comment_id + '/replies'
     return makeGetApiCall(url, params, debug=self.debug)