Пример #1
0
    def get_posts(self, migration, scan_url=None):
        """Fetches a page of posts.

    Args:
      migration: Migration
      scan_url: string, the API URL to fetch the current page of posts. If None,
        starts at the beginning.

    Returns:
      (posts, next_url). posts is a sequence of InstagramPosts.
      next_url is a string, the API URL to use for the next scan, or None
      if there is nothing more to scan.
    """
        api = InstagramAPI(
            client_id=appengine_config.INSTAGRAM_CLIENT_ID,
            client_secret=appengine_config.INSTAGRAM_CLIENT_SECRET,
            access_token=self.access_token)

        user_id = self.key().name()
        media, next_url = api.user_recent_media(user_id,
                                                with_next_url=scan_url)
        converter = as_instagram.Instagram(None)
        imedia = [
            InstagramMedia(key_name_parts=(m.id, migration.key().name()),
                           json_data=json.dumps(
                               converter.media_to_activity(m))) for m in media
        ]
        return imedia, next_url