Hi I used the doc steps and have my test user and token generated.
But I’m still facing this error message and it get me crazy. Can somebody tell me what I’m doing wrong pls ?
export const authToInstagram = functions.https.onRequest((req, res)=>{
return cookieParser()(req, res, ()=>{
const oauth2 = instagramOAuthClient();
console.log(functions.config().instagram.client_id);
// Generate a random state verification cookie.
const state = req.cookies.state || makeid(64);
res.cookie("state", state.toString(), {maxAge: 3600000, secure: true, httpOnly: true});
return new Promise((resolve, reject)=>{
const redirectUri = oauth2.authorizeURL({
redirect_uri: `${req.protocol}://us-central1-le-maki-55.cloudfunctions.net/instagramCallback`,
scope: OAUTH_SCOPES,
state: state,
});
console.log("redirect uri start here :");
console.log(redirectUri);
return res.redirect(redirectUri);
});
});
});
export const instagramCallback = functions.https.onRequest((req, res)=>{
const oauth2 = instagramOAuthClient();
return cookieParser()(req, res, ()=>{
console.log(functions.config().instagram.client_id);
functions.logger.log("Received verification state:", req.cookies.state);
functions.logger.log("Received state:", req.query.state);
if (!req.cookies.state) {
throw new Error("State cookie not set or expired. Maybe you took too long to authorize. Please try again.");
} else if (req.cookies.state !== req.query.state) {
throw new Error("State validation failed");
}
functions.logger.log("Received auth code:", req.query.code);
if (req.query.code && req.query.code != "undefined") {
const results = oauth2.getToken({
code: req.query.code.toString(),
redirect_uri: `${req.protocol}://us-central1-le-maki-55.cloudfunctions.net/instagramCallback`,
scope: OAUTH_SCOPES,
}).then((accessToken)=>{
functions.logger.log("Auth code exchange result received:", results);
// We have an Instagram access token and the user identity now.
console.log("ACCESS TOKEN");
console.log(accessToken);
const access_Token = accessToken;
const instagramUserID = accessToken.token.id;
const profilePic = accessToken.token.profile_picture;
const userName = accessToken.token.full_name;
// Create a Firebase account and get the Custom Auth Token.
createFirebaseAccount(instagramUserID, userName, profilePic, access_Token).then((token)=>{
const firebaseToken = token;
// Serve an HTML page that signs the user in and updates the user profile.
return res.json({token: firebaseToken});
});
}, (error)=>{
console.log(error);
});
} else {
throw new Error("auth code exchange failed");
}
});
});
the oauth2.getToken({
code: req.query.code.toString(),
redirect_uri: ${req.protocol}://us-central1-le-maki-55.cloudfunctions.net/instagramCallback,
scope: OAUTH_SCOPES,
})
keep saying it missing client-id… but I can clearly see it in my request. Some people say that the data should be sent through the body req but I don’t understand how to do it.