{"error":"Unauthorized","status":401,"message":"Invalid OAuth token"}

What calls are you actually doing.

Your code doesn’t make any sense.
Not sure why references to cookies are in here.