react-native - Fitbit URL 回调给出 NULL 响应
问题描述
我无法从回调 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
:
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;
}
请让我知道是否需要进一步的细节?
谢谢!
解决方案
是的,事实证明我所做的事情是正确的,除了响应应该是 301,它是一个重定向响应。
const response= {
statusCode: 301,
headers: {
"location": `app://CALLBACK RESPONSE ADDRESS?type=${provider}`
},
body: "Boom"
}
推荐阅读
- node.js - 环回 3 中数据源的配置环境问题
- javascript - HTML元素内的增量变量
- powershell - Powershell CSV文件导入行为奇怪
- c - Fortran 和 C 互操作性:从 c 接收返回值(从 Fortran 调用)
- javascript - 连接地图搜索框
- php - PHP 7.2.14 “short_open_tag = On”被忽略
- python - cleverhans 中的哪个攻击是灰盒攻击,cleverhans 库中哪个是白/黑盒攻击?
- wordpress - 如何在 XAMPP-VM (Mac OS) 上安装 WordPress 主题或插件
- python - 使用 Python 开发工具包的内置算法的 Amazon SageMaker 超参数调整错误
- excel - 从另一个单元格中选择下拉列表中的项目时自动填充单元格