400 - Error fetching data from Feedly API.

31 views
Skip to first unread message

J

unread,
May 10, 2023, 11:49:50 PM5/10/23
to Feedly Cloud
Error fetching data from Feedly API.


I think my url is needing a change its giving a 400.

anyone know why? I just want to grab the latest news.

# Feedly API endpoint
url = 'http://cloud.feedly.com/v3/streams/contents?streamId=user%40{user_id}%2Fcategory%2Fglobal.all'

J

unread,
May 10, 2023, 11:59:22 PM5/10/23
to Feedly Cloud

import requests

import pymongo

from pymongo import MongoClient


# Set up MongoDB connection

client = MongoClient('mongodb://localhost:27017/')

db = client['feedly']

collection = db['popular_stories']


# Feedly API endpoint

url = 'https://cloud.feedly.com/v3/streams/contents?streamId=user/{user_id}/category/global.all'


# Feedly API authentication token

token = 'YOUR_FEEDLY_API_TOKEN'


# User ID for the Feedly API

user_id = 'YOUR_FEEDLY_USER_ID'


# Make request to Feedly API

try:

    response = requests.get(url.format(user_id=user_id), headers={'Authorization': 'Bearer ' + token})

except requests.exceptions.RequestException as e:

    print(f'Error making request to Feedly API: {e}')

    exit()


# Check if request was successful

if response.status_code == 200:

    # Parse response JSON

    try:

        data = response.json()

    except ValueError as e:

        print(f'Error parsing JSON response from Feedly API: {e}')

        exit()


    # Get most popular stories

    popular_stories = [entry for entry in data['items'] if entry.get('engagement') and entry['engagement']['popularity'] >= 100]


    # Insert popular stories into MongoDB

    try:

        collection.insert_many(popular_stories)

    except pymongo.errors.PyMongoError as e:

        print(f'Error inserting data into MongoDB: {e}')

        exit()


    print('Successfully saved popular stories to MongoDB.')

else:

    print(f'Error fetching data from Feedly API: {response.status_code}')

    print(response.text)

Reply all
Reply to author
Forward
0 new messages