I tried using the 'linkedIn-api-client' package built on Rest.li with python code and recieved the same error. You can check it on the github 1.
import os, sys
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from flask import Flask, redirect, request
from linkedin_api.clients.auth.client import AuthClient
from linkedin_api.clients.restli.client import RestliClient
CLIENT_ID = os.getenv("CLIENT_ID")
CLIENT_SECRET = os.getenv("CLIENT_SECRET")
OAUTH2_REDIRECT_URL = os.getenv("OAUTH2_REDIRECT_URL")
print(OAUTH2_REDIRECT_URL)
app = Flask(__name__)
access_token = None
auth_client = AuthClient(
client_id=CLIENT_ID, client_secret=CLIENT_SECRET, redirect_url=OAUTH2_REDIRECT_URL
)
restli_client = RestliClient()
@app.route("/", methods=["GET"])
def main():
global access_token
if access_token == None:
return redirect(auth_client.generate_member_auth_url(scopes=["openid","profile","email"]))
else:
return restli_client.get(resource_path="/me", access_token=access_token).entity
@app.route("/oauth", methods=["GET"])
def oauth():
global access_token
args = request.args
# print(args)
auth_code = args.get("code")
if auth_code:
token_response = auth_client.exchange_auth_code_for_access_token(auth_code)
access_token = token_response.access_token
print(f"Access token: {access_token}")
return redirect("/")
else:
return "Authorization code not found", 400
if __name__ == "__main__":
app.run(host="localhost", port=3000)
When I called the link "http://127.0.0.1:3000/oauth?code={ACCESS_CODE}" with Access code, It reported the same error.
error recieved :-
{"code":"ACCESS_DENIED",
"message":"Not enough permissions to access: me.GET.NO_VERSION",
"serviceErrorCode":100,
"status":403}
Then based on the answer 1 , I tried calling the link again after few minutes and it responded with a status code '302' and without any error. The redirect link was a default app built on django, so it redirected to it.