-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Fix LinkedIn get_user() and create_post() method. #397
Conversation
@@ -97,10 +96,14 @@ async def create_post(client: RestliClient): | |||
raise ValueError( | |||
f"Error: failed to create post. Status code: {response.status_code}. Response: {response.entity}" | |||
) | |||
|
|||
response.entity["link"] = ( | |||
f"https://www.linkedin.com/feed/update/{response.entity['id']}" # craft the link manually |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the link to post created
response = client.get(resource_path="/userinfo", access_token=ACCESS_TOKEN) | ||
def get_user(client: RestliClient) -> dict: | ||
|
||
MAX_RETRIES = 3 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3 retries to prevent a weird 401 error from the Linkedin API side.
MAX_RETRIES = 3 | ||
DELAY = 1 # seconds between retries | ||
|
||
for attempt in range(1, MAX_RETRIES + 1): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems strange to me that we would need to retry this, Especially for a 401 error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I’m with you on this. Here’s the issue in detail:
Sometimes, the first time the tool makes a get_user()
request, it gets an error response like this:
{
"status": 401,
"serviceerrorcode": 65601,
"code": "revoked_access_token"
}
However, the second time it works just fine.
My theory: The OAuth process in the LinkedIn API server might be slow sometimes. After the access token is granted, the get_user() request might hit the server before the token is marked as valid in their system.
Another possible fix: I tried adding a time.sleep(2)
at the beginning of the function, and it worked. But a retry mechanism would likely make more sense.
What does this PR do:
get_user()
function.