Fitbit URL 回调给出 NULL 响应

Fitbit URL callback giving a response of 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.

问题是当我 return 到应用程序时我没有 return 代码(或任何东西),尽管我可以 console.log 它在 API.我得到的回复是 NULL

这里是 URL:

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 成功打开。

这是 API 现在在 AWS 无服务器和 Lambda 上用 Typescript 完成的

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"
    }