英文:
Use teamsfx to call dynamics global discovery service
问题
我正在尝试在我的React Tab Teams应用中使用Teams来调用动态全局发现API。
我可以在Postman上按照这里的指南使其工作:https://learn.microsoft.com/en-gb/power-apps/developer/data-platform/discovery-service?WT.mc_id=ppac_inproduct_legacy 但是,当我尝试通过Teamsfx在我的Teams React应用中调用API时,我得不到任何返回,但我收到了一个200成功代码。我已经按照以下方式实施了调用。
await teamsUserCredential.login(["User.Read", "https://globaldisco.crm.dynamics.com/user_impersonation"]);
const accessToken = await teamsUserCredential.getToken("https://globaldisco.crm.dynamics.com/user_impersonation");
const response = await fetch('https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances', {
headers: {
Authorization: `Bearer ${accessToken.token}`,
}
});
我还在应用注册中授予了管理员权限,但是我是否正确地说这在技术上不是必要的,因为登录函数应该在用户级别请求权限?
任何帮助让我开始并能够调用全局发现API都将不胜感激。
英文:
I am trying to use teams to call the dynamics global discovery API on my react tab teams app.
I can get it working on postman following the guide here: https://learn.microsoft.com/en-gb/power-apps/developer/data-platform/discovery-service?WT.mc_id=ppac_inproduct_legacy however, when I try to call the API through teamsfx on my teams react app I am getting nothing back, but I am getting a 200 success code. I have implemented the the call as below.
await teamsUserCredential.login(["User.Read","https://globaldisco.crm.dynamics.com/user_impersonation"]);
const accessToken = await teamsUserCredential.getToken("https://globaldisco.crm.dynamics.com/user_impersonation");
const response = await fetch('https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances', {
headers: {
Authorization: `Bearer ${accessToken.token}`,
}
});
I have also granted admin permission on the app registration, however am I right in saying this is not technically necessary as the login function should ask for permission at a user level?
Any help in getting me up and running so I can call the global discovery API would be much appreciated.
答案1
得分: 0
I tested using Postman and code, and it seems to be the fetch
part.
From postman:
GET https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances
After updating the fetch
to code attached below, you should be able to get the data as shown in Postman:
const accessToken = await teamsUserCredential.getToken("https://globaldisco.crm.dynamics.com/user_impersonation");
const response = await fetch('https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances', {
headers: {
Authorization: `Bearer ${accessToken!.token}`,
}
}).then((response) =>{
if (!response.ok) {throw new Error(`HTTP error! Status: ${response.status}`)}
return response.json();
}).then(data => {return data});
英文:
I tested using Postman and code, and it seems to be the fetch
part.
From postman:
GET https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances
After updating the fetch
to code attached below, you should be able to get the data as shown in Postman:
const accessToken = await teamsUserCredential.getToken("https://globaldisco.crm.dynamics.com/user_impersonation");
const response = await fetch('https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances', {
headers: {
Authorization: `Bearer ${accessToken!.token}`,
}
}).then((response) =>{
if (!response.ok) {throw new Error(`HTTP error! Status: ${response.status}`)}
return response.json();
}).then(data => {return data});
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论