Error: Initialize teams sdk failed due to not running inside Teams environment

Mayur 0 Reputation points
2024-10-28T12:20:30.7366667+00:00

Hello,

Teams sdk is not working.

it gives me error while running this code.

  const authScopes = ['User.Read.All', 'Calendars.ReadWrite', 'Mail.Send', 'MailboxSettings.Read']
      await teamsUserCredential?.login(authScopes)
      const accessToken = (await teamsUserCredential?.getToken(authScopes))!.token

Microsoft Teams Development
Microsoft Security Microsoft Graph
{count} votes

1 answer

Sort by: Most helpful
  1. Mayur 0 Reputation points
    2024-10-30T09:26:18.52+00:00

    This is my launch.json

    {
      "version": "0.2.0",
      "configurations": [
          {
              "name": "Launch Remote in Teams (Edge)",
              "type": "msedge",
              "request": "launch",
              "url": "https://teams.microsoft.com/l/app/${{TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}",
              "presentation": {
                  "group": "group 1: Teams",
                  "order": 3
              },
              "internalConsoleOptions": "neverOpen"
          },
          {
              "name": "Launch Remote in Teams (Chrome)",
              "type": "chrome",
              "request": "launch",
              "url": "https://teams.microsoft.com/l/app/${{TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}",
              "presentation": {
                  "group": "group 1: Teams",
                  "order": 3
              },
              "internalConsoleOptions": "neverOpen"
          },
          {
              "name": "Launch Remote in Outlook (Edge)",
              "type": "msedge",
              "request": "launch",
              "url": "https://outlook.office.com/host/${{M365_APP_ID}}?${account-hint}",
              "presentation": {
                  "group": "group 2: Outlook",
                  "order": 3
              },
              "internalConsoleOptions": "neverOpen"
          },
          {
              "name": "Launch Remote in Outlook (Chrome)",
              "type": "chrome",
              "request": "launch",
              "url": "https://outlook.office.com/host/${{M365_APP_ID}}?${account-hint}",
              "presentation": {
                  "group": "group 2: Outlook",
                  "order": 3
              },
              "internalConsoleOptions": "neverOpen"
          },
          {
              "name": "Launch Remote in the Microsoft 365 app (Edge)",
              "type": "msedge",
              "request": "launch",
              "url": "https://www.office.com/m365apps/${{M365_APP_ID}}?auth=2&${account-hint}",
              "presentation": {
                  "group": "group 3: the Microsoft 365 app",
                  "order": 3
              },
              "internalConsoleOptions": "neverOpen"
          },
          {
              "name": "Launch Remote in the Microsoft 365 app (Chrome)",
              "type": "chrome",
              "request": "launch",
              "url": "https://www.office.com/m365apps/${{M365_APP_ID}}?auth=2&${account-hint}",
              "presentation": {
                  "group": "group 3: the Microsoft 365 app",
                  "order": 3
              },
              "internalConsoleOptions": "neverOpen"
          },
          {
              "name": "Attach to Frontend in Teams (Edge)",
              "type": "msedge",
              "request": "launch",
              "url": "https://teams.microsoft.com/l/app/${{local:TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}",
              "presentation": {
                  "group": "all",
                  "hidden": true
              },
              "internalConsoleOptions": "neverOpen"
          },
          {
              "name": "Attach to Frontend in Teams (Chrome)",
              "type": "chrome",
              "request": "launch",
              "url": "https://teams.microsoft.com/l/app/${{local:TEAMS_APP_ID}}?installAppPackage=true&webjoin=true&${account-hint}",
              "presentation": {
                  "group": "all",
                  "hidden": true
              },
              "internalConsoleOptions": "neverOpen"
          },
          {
              "name": "Attach to Frontend in Outlook (Edge)",
              "type": "msedge",
              "request": "launch",
              "url": "https://outlook.office.com/host/${{local:M365_APP_ID}}?${account-hint}",
              "presentation": {
                  "group": "all",
                  "hidden": true
              },
              "internalConsoleOptions": "neverOpen"
          },
          {
              "name": "Attach to Frontend in Outlook (Chrome)",
              "type": "chrome",
              "request": "launch",
              "url": "https://outlook.office.com/host/${{local:M365_APP_ID}}?${account-hint}",
              "presentation": {
                  "group": "all",
                  "hidden": true
              },
              "internalConsoleOptions": "neverOpen"
          },
          {
              "name": "Attach to Frontend in the Microsoft 365 app (Edge)",
              "type": "msedge",
              "request": "launch",
              "url": "https://www.office.com/m365apps/${{local:M365_APP_ID}}?auth=2&${account-hint}",
              "presentation": {
                  "group": "all",
                  "hidden": true
              },
              "internalConsoleOptions": "neverOpen"
          },
          {
              "name": "Attach to Frontend in the Microsoft 365 app (Chrome)",
              "type": "chrome",
              "request": "launch",
              "url": "https://www.office.com/m365apps/${{local:M365_APP_ID}}?auth=2&${account-hint}",
              "presentation": {
                  "group": "all",
                  "hidden": true
              },
              "internalConsoleOptions": "neverOpen"
          }
      ],
      "compounds": [
          {
              "name": "Debug in Teams (Edge)",
              "configurations": [
                  "Attach to Frontend in Teams (Edge)"
              ],
              "preLaunchTask": "Start Teams App Locally",
              "presentation": {
                  "group": "group 1: Teams",
                  "order": 1
              },
              "stopAll": true
          },
          {
              "name": "Debug in Teams (Chrome)",
              "configurations": [
                  "Attach to Frontend in Teams (Chrome)"
              ],
              "preLaunchTask": "Start Teams App Locally",
              "presentation": {
                  "group": "group 1: Teams",
                  "order": 2
              },
              "stopAll": true
          },
          {
              "name": "Debug in Outlook (Edge)",
              "configurations": [
                  "Attach to Frontend in Outlook (Edge)"
              ],
              "preLaunchTask": "Start Teams App Locally",
              "presentation": {
                  "group": "group 2: Outlook",
                  "order": 1
              },
              "stopAll": true
          },
          {
              "name": "Debug in Outlook (Chrome)",
              "configurations": [
                  "Attach to Frontend in Outlook (Chrome)"
              ],
              "preLaunchTask": "Start Teams App Locally",
              "presentation": {
                  "group": "group 2: Outlook",
                  "order": 2
              },
              "stopAll": true
          },
          {
              "name": "Debug in the Microsoft 365 app (Edge)",
              "configurations": [
                  "Attach to Frontend in the Microsoft 365 app (Edge)"
              ],
              "preLaunchTask": "Start Teams App Locally",
              "presentation": {
                  "group": "group 3: the Microsoft 365 app",
                  "order": 1
              },
              "stopAll": true
          },
          {
              "name": "Debug in the Microsoft 365 app (Chrome)",
              "configurations": [
                  "Attach to Frontend in the Microsoft 365 app (Chrome)"
              ],
              "preLaunchTask": "Start Teams App Locally",
              "presentation": {
                  "group": "group 3: the Microsoft 365 app",
                  "order": 2
              },
              "stopAll": true
          }
      ]
    }
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.