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 上控制台.log 它。我得到的回应是 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;
}

如果需要进一步的细节,请告诉我?

谢谢!

解决方法

是的,所以结果证明我所做的是正确的,除了响应应该是 301,这是一个重定向响应。

const response= {
        statusCode: 301,headers: {
            "location": `app://CALLBACK RESPONSE ADDRESS?type=${provider}`
        },body: "Boom"
    }