【发布时间】:2021-06-03 09:18:08
【问题描述】:
我无法从回调 uri 中获得响应,如果您能给我提供任何帮助,我将不胜感激。
我正在尝试使用 Fitbit API,它要求您使用回调 url 来获取验证码。
Workflow:
1. Go to Fitbit url to get user to allow the app access to their personal data.
2. User agrees to the conditions
3. User gets redirected to my API
4. The API returns the code from (Code is located in URL and I can access it)
5. I console.log the code out to verify it
6. API returns the code
7. I work with code then exchanging it for an access token.
问题是当我返回应用程序时,我没有返回代码(或任何东西),即使我可以在 API 上进行控制台登录。我得到的回复是NULL
这是网址:
url = "https://www.fitbit.com/oauth2/authorize?response_type=code&client_id=CLIENT_ID&redirect_uri=https://REDIRECT_URL&scope=activity%20heartrate%20location%20nutrition%20profile%20settings%20sleep%20social%20weight&expires_in=604800";
然后我成功打开InAPPBrowser中的URL:
if (url !== "") {
const canOpen = await Linking.canOpenURL(url)
if (canOpen) {
try {
const isAvailable = await InAppBrowser.isAvailable()
if (isAvailable) {
const result =InAppBrowser.open(url, {
// iOS Properties
dismissButtonStyle: 'done',
preferredBarTintColor: 'gray',
preferredControlTintColor: 'white',
// Android Properties
showTitle: true,
toolbarColor: '#6200EE',
secondaryToolbarColor: 'black',
enableDefaultShare: true,
}).then((result) => {
console.log("Response:",JSON.stringify(result))
Linking.getInitialURL().then(url => {
console.log("Tests: ",url)
this._setTracker(url as string);
});
})
} else Linking.openURL(url)
} catch (error) {
console.log("Error: ",error)
}
}
}
从这里成功打开 URL。
这是现在在 AWS 无服务器和 Lambda 上的 Typescript 中完成的 API
export const handler: APIGatewayProxyHandler = async (event, _context, callback) =>{
let provider = event.path
//prints code
let x = event.queryStringParameters
console.log("Code: ",x)
const response = {
statusCode: 200,
body: "Success"
};
return response;
}
如果需要更多详细信息,请告诉我?
谢谢!
【问题讨论】:
标签: react-native aws-lambda react-native-android react-native-ios aws-serverless