Reputation: 3
When I hardcode a value it works perfectly
username = "leomessi";
let id = await (await fetch(`https://www.instagram.com/${username}/?__a=1`)).json();
console.log(id.graphql.user.id);
But when I make it a function
const userToID = (username) => {
let id = await (await fetch(`https://www.instagram.com/${username}/?__a=1`)).json();
return id.graphql.user.id;
}
it says Uncaught SyntaxError: missing ) after argument list
Upvotes: 0
Views: 760
Reputation: 2462
You need to use the async
keyword for functions where you want to await
const userToID = async (username) => {
let id = await (await fetch(`https://www.instagram.com/${username}/?__a=1`)).json();
return id.graphql.user.id;
}
Upvotes: 0
Reputation: 3126
So first of all, you are using await
. This means you should expect to define your wrapping function as async
.
const userToID = async (username) => {
let id = await (await fetch(`https://www.instagram.com/${username}/?__a=1`)).json();
return id.graphql.user.id;
}
Upvotes: 2