示例#1
0
    def get_batch(
        self,
        ids: Optional[Union[str, list, tuple]],
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[Dict[str, IgBusComment], dict]:
        """
        Get batch business comment information by ids

        :param ids: IDs for the comments.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dict of dataclass for IgBusComment.
            Or return json data. Default is false.
        :return: Business medias information.
        """
        ids = enf_comma_separated(field="ids", value=ids)

        if fields is None:
            fields = const.IG_BUSINESS_COMMENT_PUBLIC_FIELDS

        data = self.client.get_objects(ids=ids,
                                       fields=enf_comma_separated(
                                           field="fields", value=fields))
        if return_json:
            return data
        else:
            return {
                comment_id: IgBusComment.new_from_json_dict(item)
                for comment_id, item in data.items()
            }
示例#2
0
    def get_batch(
        self,
        ids: Optional[Union[str, list, tuple]],
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[Dict[str, Page], dict]:
        """
        Get batch pages information by ids.

        :param ids: IDs for the pages.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for page.
            Or return json data. Default is false.
        :return: Pages information.
        """

        ids = enf_comma_separated(field="ids", value=ids)

        if fields is None:
            fields = const.PAGE_PUBLIC_FIELDS

        data = self.client.get_objects(ids=ids,
                                       fields=enf_comma_separated(
                                           field="fields", value=fields))
        if return_json:
            return data
        else:
            return {
                page_id: Page.new_from_json_dict(item)
                for page_id, item in data.items()
            }
示例#3
0
    def get_content_publishing_limit(
        self,
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[IgBusPublishLimitResponse, dict]:
        """
        Get user's current content publishing usage.

        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for IgBusPublishLimitResponse.
            Or return json data. Default is false.
        :return: Business content publish limit response information.
        """

        if fields is None:
            fields = const.IG_BUSINESS_CONTENT_PUBLISH_LIMIT_FIELDS

        data = self.client.get_connection(
            object_id=self.client.instagram_business_id,
            connection="content_publishing_limit",
            fields=enf_comma_separated(field="fields", value=fields),
        )
        if return_json:
            return data
        else:
            return IgBusPublishLimitResponse.new_from_json_dict(data)
示例#4
0
    def get_accounts(
        self,
        fields: Optional[Union[str, list, dict]] = None,
        count: Optional[int] = 10,
        limit: Optional[int] = 10,
        return_json: bool = False,
    ) -> Union[ApplicationAccountsResponse, dict]:
        """
        Represents a collection of test users on an app.

        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param count: The total count for you to get data.
        :param limit: Each request retrieve objects count.
            It should no more than 100. Default is None will use api default limit.
        :param return_json: Set to false will return a dataclass for post.
            Or return json data. Default is false.
        :return: Application accounts information.
        """

        if fields is None:
            fields = const.APPLICATION_ACCOUNT_PUBLIC_FIELDS

        data = self.client.get_full_connections(
            object_id=self.client.app_id,
            connection="accounts",
            count=count,
            limit=limit,
            fields=enf_comma_separated(field="fields", value=fields),
        )
        if return_json:
            return data
        else:
            return ApplicationAccountsResponse.new_from_json_dict(data)
示例#5
0
    def get_children(
        self,
        media_id: str,
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[IgBasicMediaChildren, dict]:
        """
        Get a collection of image and video Media on an album Media.

        :param media_id: ID for the album media.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for IgBasicMediaChildren.
            Or return json data. Default is false.
        :return: Media children response information.
        """

        if fields is None:
            fields = const.IG_BASIC_MEDIA_CHILDREN_FIELDS

        data = self.client.get_connection(
            object_id=media_id,
            connection="children",
            fields=enf_comma_separated(field="fields", value=fields),
        )
        if return_json:
            return data
        else:
            return IgBasicMediaChildren.new_from_json_dict(data)
示例#6
0
    def get_info(
        self,
        conversation_id: Optional[str],
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[Conversation, dict]:
        """
        Get information about a Facebook Conversation.

        :param conversation_id: ID for the Conversation.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for Conversation.
            Or return json data. Default is false.
        :return: Conversation information.
        """

        if fields is None:
            fields = const.CONVERSATION_FIELDS

        data = self.client.get_object(
            object_id=conversation_id,
            fields=enf_comma_separated(field="fields", value=fields),
        )
        if return_json:
            return data
        else:
            return Conversation.new_from_json_dict(data=data)
示例#7
0
    def get_info(
        self,
        group_id: str,
        fields: Optional[Union[str, list, tuple]] = None,
        return_json=False,
    ) -> Union[Group, dict]:
        """
        Get information about a Facebook Group.

        :param group_id: ID for the group.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for page.
            Or return json data. Default is false.
        :return: Group information.
        """
        if fields is None:
            fields = const.GROUP_PUBLIC_FIELDS
        data = self.client.get_object(object_id=group_id,
                                      fields=enf_comma_separated(
                                          field="fields", value=fields))
        if return_json:
            return data
        else:
            return Group.new_from_json_dict(data=data)
示例#8
0
    def get_info(
        self,
        user_id: str,
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[User, dict]:
        """
        Get information about a Facebook User.

        :param user_id: ID for user.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for user.
        Or return json data. Default is false.
        :return: User information.
        """
        if fields is None:
            fields = const.USER_PUBLIC_FIELDS

        data = self.client.get_object(
            object_id=user_id,
            fields=enf_comma_separated(field="fields", value=fields),
        )
        if return_json:
            return data
        else:
            return User.new_from_json_dict(data=data)
示例#9
0
    def get_insights(
        self,
        media_id: str,
        metric: Union[str, list, tuple],
        return_json: bool = False,
    ) -> Union[IgBusInsightsResponse, dict]:
        """
        Get insights data on a media

        :param media_id: ID for the media.
        :param metric: A comma-separated list of Metrics you want returned.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for IgBusPublishLimitResponse.
            Or return json data. Default is false.
        :return: Media insights response information.
        """
        data = self.client.get_connection(
            object_id=media_id,
            connection="insights",
            metric=enf_comma_separated(field="metric", value=metric),
        )

        if return_json:
            return data
        else:
            return IgBusInsightsResponse.new_from_json_dict(data)
示例#10
0
    def get_info(
        self,
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[IgBusUser, dict]:
        """
        Get information about an Instagram Business Account or an Instagram Creator Account.

        Note:

            Now this can only get user info by user's access token.

        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for Account.
            Or return json data. Default is false.
        :return: IG Business User information.
        """
        if fields is None:
            fields = const.IG_BUSINESS_USER_PUBLIC_FIELDS

        data = self.client.get_object(
            object_id=self.client.instagram_business_id,
            fields=enf_comma_separated(field="fields", value=fields),
        )
        if return_json:
            return data
        else:
            return IgBusUser.new_from_json_dict(data=data)
示例#11
0
    def get_info(
        self,
        live_video_id: Optional[str],
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[LiveVideo, dict]:
        """
        Get information about a Facebook Live Video.

        :param live_video_id: ID for the Live Video.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for Live Video.
            Or return json data. Default is false.
        :return: Live Video information.
        """

        if fields is None:
            fields = const.LIVE_VIDEO_PUBLIC_FIELDS

        data = self.client.get_object(
            object_id=live_video_id,
            fields=enf_comma_separated(field="fields", value=fields),
        )
        if return_json:
            return data
        else:
            return LiveVideo.new_from_json_dict(data=data)
示例#12
0
    def get_info(
        self,
        post_id: Optional[str],
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[Post, dict]:
        """
        Get information about a Facebook post

        :param post_id: ID for the post.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for post.
            Or return json data. Default is false.
        :return: Post information
        """

        if fields is None:
            fields = const.POST_PUBLIC_FIELDS + const.POST_CONNECTIONS_SUMMERY_FIELDS

        data = self.client.get_object(object_id=post_id,
                                      fields=enf_comma_separated(
                                          field="fields", value=fields))
        if return_json:
            return data
        else:
            return Post.new_from_json_dict(data=data)
示例#13
0
    def get_info(
        self,
        user_id: Optional[str] = "me",
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[IgBasicUser, dict]:
        """
        Represents an Instagram user profile.

        :param user_id: ID for the user, matched the access token.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for Account.
            Or return json data. Default is false.
        :return: IG Basic User information.
        """
        if fields is None:
            fields = const.IG_BASIC_USER_FIELDS

        data = self.client.get_object(
            object_id=user_id,
            fields=enf_comma_separated(field="fields", value=fields),
        )
        if return_json:
            return data
        else:
            return IgBasicUser.new_from_json_dict(data=data)
示例#14
0
    def discovery_user(
        self,
        username: str,
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[IgBusDiscoveryUserResponse, dict]:
        """
        Get other business account info by username.

        :param username: Username to get data.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for IgBusDiscoveryUserResponse.
            Or return json data. Default is false.
        :return: Business discovery user response information.
        """

        if fields is None:
            fields = const.IG_BUSINESS_USER_PUBLIC_FIELDS

        metric = enf_comma_separated(field="fields", value=fields)

        data = self.client.get_object(
            object_id=self.client.instagram_business_id,
            fields=f"business_discovery.username({username}){{{metric}}}",
        )
        if return_json:
            return data
        else:
            return IgBusDiscoveryUserResponse.new_from_json_dict(data=data)
示例#15
0
    def get_info(
        self,
        comment_id: str,
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[IgBusComment, dict]:
        """
        Get information about a Business comment.

        :param comment_id: ID for Comment.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for IgBusComment.
            Or return json data. Default is false.
        :return: Business comment information.
        """
        if fields is None:
            fields = const.IG_BUSINESS_MEDIA_PUBLIC_FIELDS

        data = self.client.get_object(
            object_id=comment_id,
            fields=enf_comma_separated(field="fields", value=fields),
        )
        if return_json:
            return data
        else:
            return IgBusComment.new_from_json_dict(data=data)
示例#16
0
    def get_tagged_media(
        self,
        fields: Optional[Union[str, list, tuple]] = None,
        count: Optional[int] = 25,
        limit: Optional[int] = 25,
        return_json=False,
    ) -> Union[IgBusMediaResponse, dict]:
        """
        Get list of Media objects in which user has been tagged by another Instagram user.

        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param count: The total count for you to get data.
        :param limit: Each request retrieve objects count.
            It should no more than 100. Default is None will use api default limit.
        :param return_json: Set to false will return a dataclass for IgBusMediaResponse.
            Or return json data. Default is false.
        :return: Tagged user medias response information.
        """

        if fields is None:
            fields = const.IG_BUSINESS_MEDIA_PUBLIC_FIELDS

        data = self.client.get_full_connections(
            object_id=self.client.instagram_business_id,
            connection="tags",
            count=count,
            limit=limit,
            fields=enf_comma_separated(field="fields", value=fields),
        )
        if return_json:
            return data
        else:
            return IgBusMediaResponse.new_from_json_dict(data)
示例#17
0
    def get_recently_searched_hashtags(
        self,
        fields: Optional[Union[str, list, tuple]] = None,
        count: Optional[int] = 25,
        limit: Optional[int] = 25,
        return_json=False,
    ) -> Union[IgBusHashtagsResponse, dict]:
        """
        Get the IG Hashtags that user has searched for within the last 7 days.

        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param count: The total count for you to get data. Maximum is 30.
        :param limit: Each request retrieve objects count. Up to 30.
        :param return_json: Set to false will return a dataclass for IgBusHashtagsResponse.
            Or return json data. Default is false.
        :return: Recently searched hashtags response information.
        """

        if fields is None:
            fields = const.IG_BUSINESS_HASHTAG_PUBLIC_FIELDS

        data = self.client.get_full_connections(
            object_id=self.client.instagram_business_id,
            connection="recently_searched_hashtags",
            fields=enf_comma_separated(field="fields", value=fields),
            count=count,
            limit=limit,
        )
        if return_json:
            return data
        else:
            return IgBusHashtagsResponse.new_from_json_dict(data)
示例#18
0
    def get_mentioned_media(
        self,
        media_id: str,
        fields: Optional[Union[str, list, tuple]] = None,
        return_json=False,
    ) -> Union[IgBusMentionedMediaResponse, dict]:
        """
        Get data on an IG Media in which user has been @mentioned in a caption by another Instagram user.

        :param media_id: ID for media which the user has been @mentioned in a caption
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for IgBusMentionedMediaResponse.
            Or return json data. Default is false.
        :return: Mentioned media response.
        """

        if fields is None:
            fields = const.IG_BUSINESS_MENTION_MEDIA_FIELDS
        fields_inline = enf_comma_separated(field="fields", value=fields)

        data = self.client.get_object(
            object_id=self.client.instagram_business_id,
            fields=f"mentioned_media.media_id({media_id}){{{fields_inline}}}",
        )
        if return_json:
            return data
        else:
            return IgBusMentionedMediaResponse.new_from_json_dict(data)
示例#19
0
    def get_info(
        self,
        media_id: str,
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[IgBasicMedia, dict]:
        """
        Represents an image, video, or album media data.

        :param media_id: ID for Media.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for IgBasicMedia.
            Or return json data. Default is false.
        :return: Basic media information.
        """

        if fields is None:
            fields = const.IG_BASIC_MEDIA_FIELDS

        data = self.client.get_object(
            object_id=media_id,
            fields=enf_comma_separated(field="fields", value=fields),
        )

        if return_json:
            return data
        else:
            return IgBasicMedia.new_from_json_dict(data)
示例#20
0
    def get_info(
        self,
        fields: Optional[Union[str, list, tuple]] = None,
        return_json: bool = False,
    ) -> Union[Application, dict]:
        """
        Get information for current facebook Application. Need app token.

        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param return_json: Set to false will return a dataclass for Application.
            Or return json data. Default is false.
        :return: Application information.
        """
        if fields is None:
            fields = const.APPLICATION_PUBLIC_FIELDS

        data = self.client.get_object(
            object_id=self.client.app_id,
            fields=enf_comma_separated(field="fields", value=fields),
        )
        if return_json:
            return data
        else:
            return Application.new_from_json_dict(data=data)
示例#21
0
def test_enf_comma_separated():
    assert enf_comma_separated("fields", "f1") == "f1"
    assert enf_comma_separated("fields", ["f1", "f2"]) == "f1,f2"
    assert enf_comma_separated("fields", ["f1", "f2", "f2"]) == "f1,f2"
    assert enf_comma_separated("fields", ("f1", "f2")) == "f1,f2"

    with pytest.raises(LibraryError):
        enf_comma_separated("id", 1)

    with pytest.raises(LibraryError):
        enf_comma_separated("id", [None, None])
示例#22
0
    def get_comments(
        self,
        object_id: str,
        fields: Optional[Union[str, list, dict]] = None,
        filter_type: Optional[str] = None,
        summary: Optional[bool] = None,
        since: Optional[str] = None,
        until: Optional[str] = None,
        count: Optional[int] = 10,
        limit: Optional[int] = 10,
        return_json: bool = False,
        **kwargs,
    ) -> Union[CommentsResponse, dict]:
        """
        Get lists of comments on a Facebook object.

        :param object_id: ID for the facebook object.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param filter_type: This determines which comments are returned when comment replies are available.
            It can be either:
                - toplevel : Default, return all top-level comments
                - stream : All-level comments in chronological order.
        :param summary: Is return the aggregated information about the edge,
        :param since: A Unix timestamp or strtotime data value that points to the start of data.
        :param until: A Unix timestamp or strtotime data value that points to the end of data.
        :param count: The total count for you to get data.
        :param limit: Each request retrieve objects count.
            It should no more than 100. Default is None will use api default limit.
        :param return_json: Set to false will return a dataclass for Comment.
            Or return json data. Default is false.
        :param kwargs: Additional parameters for different object.
        :return: Comments response information
        """

        if fields is None:
            fields = const.COMMENT_PUBLIC_FIELDS

        data = self.client.get_full_connections(
            object_id=object_id,
            connection="comments",
            count=count,
            limit=limit,
            fields=enf_comma_separated(field="fields", value=fields),
            since=since,
            until=until,
            filter=filter_type,
            summary=summary,
            **kwargs,
        )

        if return_json:
            return data
        else:
            return CommentsResponse.new_from_json_dict(data)
示例#23
0
    def discovery_user_medias(
        self,
        username: str,
        fields: Optional[Union[str, list, tuple]] = None,
        limit: Optional[int] = None,
        since: Optional[str] = None,
        until: Optional[str] = None,
        after: Optional[str] = None,
        before: Optional[str] = None,
        return_json: bool = False,
    ) -> Union[IgBusDiscoveryUserMediaResponse, dict]:
        """
        Get other business account's media by username.

        :param username: Username to get data.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param limit: Each request retrieve objects count.
            It should no more than 100. Default is None will use api default limit.
        :param since: A Unix timestamp or strtotime data value that points to the start of data.
        :param until: A Unix timestamp or strtotime data value that points to the end of data.
        :param after: The cursor that points to the end of the page of data that has been returned.
        :param before: The cursor that points to the start of the page of data that has been returned.
        :param return_json: Set to false will return a dataclass for IgBusDiscoveryUserMediaResponse.
            Or return json data. Default is false.
        :return: Business discovery media response information.
        """

        if fields is None:
            fields = const.IG_BUSINESS_MEDIA_PUBLIC_FIELDS
        metric = enf_comma_separated(field="fields", value=fields)

        limit_str = f".limit({limit})" if limit is not None else ""
        after_str = f".after({after})" if after is not None else ""
        before_str = f".before({before})" if before is not None else ""
        since_str = f".since({since})" if since is not None else ""
        until_str = f".until({until})" if until is not None else ""

        data = self.client.get_object(
            object_id=self.client.instagram_business_id,
            fields=
            (f"business_discovery.username({username})"
             f"{{media{after_str}{before_str}{since_str}{until_str}{limit_str}{{{metric}}}}}"
             ),
        )

        if return_json:
            return data
        else:
            return IgBusDiscoveryUserMediaResponse.new_from_json_dict(data)
示例#24
0
    def get_insights(
        self,
        metric: Union[str, list, tuple],
        period: str,
        since: Optional[str] = None,
        until: Optional[str] = None,
        user_id: Optional[str] = None,
        access_token: Optional[str] = None,
        return_json: bool = False,
    ) -> Union[IgBusInsightsResponse, dict]:
        """
        Get social interaction metrics on an IG User.

        :param metric: Comma-separated id string for insights metrics which you want.
            You can also pass this with an id list, tuple.
        :param period: Period to aggregation data.
            Accepted parameters: lifetime,day,week,days_28
        :param since: Lower bound of the time range to fetch data. Need Unix timestamps.
        :param until: Upper bound of the time range to fetch data. Need Unix timestamps.
            Notice: time range may not more than 30 days.
        :param user_id: ID for business user to get insights.
        :param access_token: Access token with permissions for user_id.
        :param return_json: Set to false will return a dataclass for Insights.
            Or return json data. Default is false.
        :return: Business user insights response information.
        """

        if user_id is None:
            user_id = self.client.instagram_business_id

        args = {
            "metric": enf_comma_separated(field="metric", value=metric),
            "period": period,
            "since": since,
            "until": until,
        }
        if access_token:
            args["access_token"] = access_token

        data = self.client.get_connection(
            object_id=user_id,
            connection="insights",
            **args,
        )
        if return_json:
            return data
        else:
            return IgBusInsightsResponse.new_from_json_dict(data)
示例#25
0
    def _get_feed(
        self,
        object_id: str,
        fields: Optional[Union[str, list, dict]] = None,
        since: Optional[str] = None,
        until: Optional[str] = None,
        count: Optional[int] = 10,
        limit: Optional[int] = 10,
        source: Optional[str] = "feed",
        return_json: bool = False,
        **kwargs,
    ) -> Union[FeedResponse, dict]:
        """
        Get feed of a Facebook object.

        :param object_id: ID for object to get feeds.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param since: A Unix timestamp or strtotime data value that points to the start of data.
        :param until: A Unix timestamp or strtotime data value that points to the end of data.
        :param count: The total count for you to get data.
        :param limit: Each request retrieve objects count.
            It should no more than 100. Default is None will use api default limit.
        :param source: Resource type. Valid values maybe feed/posts/tagged/published_posts depend on object type.
        :param return_json: Set to false will return a dataclass for post.
            Or return json data. Default is false.
        :param kwargs: Additional parameters for different object.
        :return: feed response information
        """

        if fields is None:
            fields = const.POST_PUBLIC_FIELDS + const.POST_CONNECTIONS_SUMMERY_FIELDS

        data = self.client.get_full_connections(
            object_id=object_id,
            connection=source,
            count=count,
            limit=limit,
            fields=enf_comma_separated(field="fields", value=fields),
            since=since,
            until=until,
            **kwargs,
        )
        if return_json:
            return data
        else:
            return FeedResponse.new_from_json_dict(data)
示例#26
0
    def get_videos(
        self,
        object_id: str,
        fields: Optional[Union[str, list, dict]] = None,
        since: Optional[str] = None,
        until: Optional[str] = None,
        count: Optional[int] = 10,
        limit: Optional[int] = 10,
        return_json: bool = False,
        **kwargs,
    ) -> Union[VideosResponse, dict]:
        """
        Get a list of videos on a Facebook object.

        :param object_id: ID for object(page,user,group)
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param since: A Unix timestamp or strtotime data value that points to the start of data.
        :param until: A Unix timestamp or strtotime data value that points to the end of data.
        :param count: The total count for you to get data.
        :param limit: Each request retrieve objects count.
            It should no more than 100. Default is None will use api default limit.
        :param return_json: Set to false will return a list dataclass for Videos.
            Or return json data. Default is false.
        :param kwargs: Additional parameters for different object.
        :return: Videos response information
        """

        if fields is None:
            fields = const.VIDEO_PUBLIC_FIELDS

        data = self.client.get_full_connections(
            object_id=object_id,
            connection="videos",
            count=count,
            limit=limit,
            fields=enf_comma_separated(field="fields", value=fields),
            since=since,
            until=until,
            **kwargs,
        )

        if return_json:
            return data
        else:
            return VideosResponse.new_from_json_dict(data)
示例#27
0
    def get_accounts(
        self,
        user_id: str,
        fields: Optional[Union[str, list, tuple]] = None,
        is_place: Optional[bool] = None,
        is_promotable: Optional[bool] = None,
        summary: Optional[bool] = None,
        count: Optional[int] = 10,
        limit: Optional[int] = 10,
        return_json: bool = False,
    ) -> Union[PagesResponse, dict]:
        """
        Get the Facebook Pages that a person owns or is able to perform tasks on.

        :param user_id: ID for the user.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param is_place: If specified,filter pages based on whetherthey are places or not.
        :param is_promotable: If specified, filter pages based on whether they can be promoted or not.
        :param summary: Whether aggregated information about the edge, such as counts.
        :param count: The total count for you to get data.
        :param limit: Each request retrieve objects count.
            It should no more than 100. Default is None will use api default limit.
        :param return_json: Set to false will return a dataclass for Page.
            Or return json data. Default is false.
        :return: Pages information and paging
        """
        if fields is None:
            fields = const.PAGE_PUBLIC_FIELDS

        data = self.client.get_full_connections(
            object_id=user_id,
            connection="accounts",
            count=count,
            limit=limit,
            fields=enf_comma_separated(field="fields", value=fields),
            is_place=is_place,
            is_promotable=is_promotable,
            summary=summary,
        )
        if return_json:
            return data
        else:
            return PagesResponse.new_from_json_dict(data)
示例#28
0
    def get_media(
        self,
        user_id: Optional[str] = "me",
        fields: Optional[Union[str, list, tuple]] = None,
        since: Optional[str] = None,
        until: Optional[str] = None,
        count: Optional[int] = 10,
        limit: Optional[int] = 10,
        return_json=False,
    ) -> Union[IgBasicMediaResponse, dict]:
        """
        Represents a collection of Media on a User. Maximum of 10K of the most recently created media.

        :param user_id: ID for the user, matched the access token.
        :param fields:
        :param since: A Unix timestamp or strtotime data value that points to the start of data.
        :param until: A Unix timestamp or strtotime data value that points to the end of data.
        :param count: The total count for you to get data.
        :param limit: Each request retrieve objects count.
            It should no more than 100. Default is None will use api default limit.
        :param return_json: Set to false will return a dataclass for IgBasicMediaResponse.
            Or return json data. Default is false.
        :return: Media response information.
        """

        if fields is None:
            fields = const.IG_BASIC_MEDIA_FIELDS

        data = self.client.get_full_connections(
            object_id=user_id,
            connection="media",
            count=count,
            limit=limit,
            fields=enf_comma_separated(field="fields", value=fields),
            since=since,
            until=until,
        )
        if return_json:
            return data
        else:
            return IgBasicMediaResponse.new_from_json_dict(data)
示例#29
0
    def get_media(
        self,
        fields: Optional[Union[str, list, tuple]] = None,
        since: Optional[str] = None,
        until: Optional[str] = None,
        count: Optional[int] = 10,
        limit: Optional[int] = 10,
        return_json=False,
    ) -> Union[IgBusMediaResponse, dict]:
        """
        Get user's media. This only can return max 10k medias.

        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param since: A Unix timestamp or strtotime data value that points to the start of data.
        :param until: A Unix timestamp or strtotime data value that points to the end of data.
        :param count: The total count for you to get data.
        :param limit: Each request retrieve objects count.
            It should no more than 100. Default is None will use api default limit.
        :param return_json: Set to false will return a dataclass for IgBusMediaResponse.
            Or return json data. Default is false.
        :return: Media response information.
        """

        if fields is None:
            fields = const.IG_BUSINESS_MEDIA_PUBLIC_FIELDS

        data = self.client.get_full_connections(
            object_id=self.client.instagram_business_id,
            connection="media",
            count=count,
            limit=limit,
            fields=enf_comma_separated(field="fields", value=fields),
            since=since,
            until=until,
        )
        if return_json:
            return data
        else:
            return IgBusMediaResponse.new_from_json_dict(data)
示例#30
0
    def get_top_media(
        self,
        hashtag_id: str,
        fields: Optional[Union[str, list, tuple]] = None,
        count: Optional[int] = 10,
        limit: Optional[int] = 10,
        return_json: bool = False,
    ) -> Union[IgBusMediaResponse, dict]:
        """
        Get the Most Popular Hashtagged Media

        :param hashtag_id: ID for the hashtag.
        :param fields: Comma-separated id string for data fields which you want.
            You can also pass this with an id list, tuple.
        :param count: The total count for you to get data.
        :param limit: Each request retrieve objects count.
            It should no more than 50. Default is None will use api default limit.
        :param return_json: Set to false will return a dataclass for IgBusMediaResponse.
            Or return json data. Default is false.
        :return: Media response information.
        """

        if fields is None:
            fields = const.IG_BUSINESS_MEDIA_PUBLIC_FIELDS

        data = self.client.get_full_connections(
            object_id=hashtag_id,
            connection="top_media",
            user_id=self.client.instagram_business_id,
            fields=enf_comma_separated(field="fields", value=fields),
            count=count,
            limit=limit,
        )

        if return_json:
            return data
        else:
            return IgBusMediaResponse.new_from_json_dict(data)