从应用程序名称获取应用程序 guid - 通过代码
Get app guid from app name - via code
我和节点应用程序 mainApp
运行 在 CF space 上,在这个节点应用程序中我得到 其他 应用程序 name
(部署在同一个 space),我想从中获取应用程序 guid,我该怎么做?
这是我尝试过的方法(我尝试获取此 space 中的所有应用程序并从 guid
中搜索特定应用程序,但我得到了 http 401 - unauthorized
,
any idea how can I get from app that deployed to CF the app app guid (suppose I've the app name )
There is a better way to achieve this ?
getAllApps: () => {
return new Promise((resolve, reject) => {
rp({
uri: 'https://' + CF_API + '/v2/apps',
json: true
}).then((data) => {
"use strict";
console.log("apps data: " + data);
resolve(data);
});
})
您必须首先获取访问令牌并将其传递到您问题中的请求的 header 中。
请参阅下面将获取应用程序 GUID 的示例:
var request = require('request-promise');
request({
"method":"POST",
"uri": "https://login.ng.bluemix.net/UAALoginServerWAR/oauth/token",
"json": true,
"headers": {
"content-type": "application/x-www-form-urlencoded",
"authorization": "Basic Y2Y6",
"accept": "application/json"
},
"form" : {
"grant_type": "password",
"username": "<your Bluemix id>",
"password": "<your Bluemix password>"
}
}).then(function(response) {
return response.access_token;
}).then(function(token) {
return request({
"method":"GET",
"uri": "https://api.ng.bluemix.net/v2/apps",
"qs": {
"q": "name:yourappname"
},
"json": true,
"headers": {
"accept": "application/json",
"authorization": "bearer " + token
}
}).then(function (response) {
console.log(response.resources[0].metadata.guid);
});
});
检查这个:
http://apidocs.cloudfoundry.org/272/apps/get_app_summary.html
使用 httpclient API,您可以获取任何语言的应用程序名称。
我和节点应用程序 mainApp
运行 在 CF space 上,在这个节点应用程序中我得到 其他 应用程序 name
(部署在同一个 space),我想从中获取应用程序 guid,我该怎么做?
这是我尝试过的方法(我尝试获取此 space 中的所有应用程序并从 guid
中搜索特定应用程序,但我得到了 http 401 - unauthorized
,
any idea how can I get from app that deployed to CF the app app guid (suppose I've the app name )
There is a better way to achieve this ?
getAllApps: () => {
return new Promise((resolve, reject) => {
rp({
uri: 'https://' + CF_API + '/v2/apps',
json: true
}).then((data) => {
"use strict";
console.log("apps data: " + data);
resolve(data);
});
})
您必须首先获取访问令牌并将其传递到您问题中的请求的 header 中。 请参阅下面将获取应用程序 GUID 的示例:
var request = require('request-promise');
request({
"method":"POST",
"uri": "https://login.ng.bluemix.net/UAALoginServerWAR/oauth/token",
"json": true,
"headers": {
"content-type": "application/x-www-form-urlencoded",
"authorization": "Basic Y2Y6",
"accept": "application/json"
},
"form" : {
"grant_type": "password",
"username": "<your Bluemix id>",
"password": "<your Bluemix password>"
}
}).then(function(response) {
return response.access_token;
}).then(function(token) {
return request({
"method":"GET",
"uri": "https://api.ng.bluemix.net/v2/apps",
"qs": {
"q": "name:yourappname"
},
"json": true,
"headers": {
"accept": "application/json",
"authorization": "bearer " + token
}
}).then(function (response) {
console.log(response.resources[0].metadata.guid);
});
});
检查这个:
http://apidocs.cloudfoundry.org/272/apps/get_app_summary.html
使用 httpclient API,您可以获取任何语言的应用程序名称。