Example #1
0
    def get_pictures(
            self,
            ids,  # type: Optional[Union[str, List, Tuple, Set]]
            pic_type=None,  # type: Optional[str]
            return_json=False  # type: bool
    ):
        # type: (...) -> dict
        """
        :param ids: Comma-separated id(username) string for page which you want to get.
        You can also pass this with an id list, tuple, set.
        :param pic_type: The picture type.
        :param return_json: Set to false will return a dict of Comment instances.
        Or return json data. Default is false.
        """
        if pic_type is not None and pic_type not in constant.FB_PAGE_PICTURE_TYPE:
            raise PyFacebookException(
                ErrorMessage(
                    code=ErrorCode.INVALID_PARAMS,
                    message=
                    "For field picture: pic_type must be one of the following values: {}"
                    .format(', '.join(constant.FB_PAGE_PICTURE_TYPE))))

        args = {
            "ids": enf_comma_separated("ids", ids),
            'redirect': 0,  # if set 0 the api will return json response.
            'type': 'normal' if pic_type is None else pic_type,
        }
        resp = self._request(method='GET',
                             path='{0}/picture'.format(self.version),
                             args=args)

        data = self._parse_response(resp)

        res = {}
        for _id, p_data in iteritems(data):
            picture_data = p_data["data"]
            if return_json:
                res[_id] = picture_data
            else:
                res[_id] = ProfilePictureSource.new_from_json_dict(
                    picture_data)
        return res
Example #2
0
    def get_picture(self,
                    page_id,  # type: str
                    pic_type=None,  # type: Optional[str]
                    return_json=False  # type: bool
                    ):
        # type: (...) -> Union[ProfilePictureSource, dict]
        """
        Retrieve the page's picture.

        :param page_id: The id for picture you want to retrieve data.
        :param pic_type: The picture type.
        :param return_json: Set to false will return a dict of Comment instances.
        Or return json data. Default is false.
        """

        if pic_type is not None and pic_type not in constant.FB_PAGE_PICTURE_TYPE:
            raise PyFacebookException(ErrorMessage(
                code=ErrorCode.INVALID_PARAMS,
                message="For field picture: pic_type must be one of the following values: {}".format(
                    ', '.join(constant.FB_PAGE_PICTURE_TYPE)
                )))

        args = {
            'redirect': 0,  # if set 0 the api will return json response.
            'type': 'normal' if pic_type is None else pic_type,
        }

        resp = self._request(
            method='GET',
            path='{0}/{1}/picture'.format(self.version, page_id),
            args=args
        )

        data = self._parse_response(resp)
        data = replace_from_keyword_in_json(data=data)

        if return_json:
            return data['data']
        else:
            return ProfilePictureSource.new_from_json_dict(data['data'])