Ibm cloud 如何查找IBMAPI的用户id和密码?
我是IBMAPI的初学者。我刚刚启动了一个IBM自然语言理解服务。然而,我得到的是API密钥,而不是用户id和密码。像这样:Ibm cloud 如何查找IBMAPI的用户id和密码?,ibm-cloud,Ibm Cloud,我是IBMAPI的初学者。我刚刚启动了一个IBM自然语言理解服务。然而,我得到的是API密钥,而不是用户id和密码。像这样: { "apikey": "••••••••••••••••••••••••••••••••••••••••••••", "iam_apikey_description": "Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:natural
{
"apikey": "••••••••••••••••••••••••••••••••••••••••••••",
"iam_apikey_description": "Auto generated apikey during resource-key operation for Instance - crn:v1:bluemix:public:natural-language-understanding:us-east:a/6514bcdaafbc465498a244edb484cbe5:53e5f23b-f255-4d6c-b48d-cfce09c975b1::",
"iam_apikey_name": "auto-generated-apikey-51f2d016-d3ec-46bc-8be7-496ae621983d",
"iam_role_crn": "crn:v1:bluemix:public:iam::::serviceRole:Manager",
"iam_serviceid_crn": "crn:v1:bluemix:public:iam-identity::a/6514bcdaafbc465498a244edb484cbe5::serviceid:ServiceId-d83a34de-5860-443a-817a-b3cb3fb44e2a",
"url": "https://gateway-wdc.watsonplatform.net/natural-language-understanding/api"
}
在下面的示例中,它显示我需要一个用户id和密码。我在哪里可以找到它们?谢谢
import json
from watson_developer_cloud import NaturalLanguageUnderstandingV1
from watson_developer_cloud.natural_language_understanding_v1 \
import Features, EntitiesOptions, KeywordsOptions
natural_language_understanding = NaturalLanguageUnderstandingV1(
username='username',
password='password',
version='2018-03-16')
response = natural_language_understanding.analyze(
text='IBM is an American multinational technology company '
'headquartered in Armonk, New York, United States, '
'with operations in over 170 countries.',
features=Features(
entities=EntitiesOptions(
emotion=True,
sentiment=True,
limit=2),
keywords=KeywordsOptions(
emotion=True,
sentiment=True,
limit=2)))
print(json.dumps(response, indent=2))
根据和中的说明,您的应用程序需要使用那里的API密钥从Identity and Access Manager请求承载令牌。这在实例的中有详细说明
因此,如果您的实例是在2018年5月28日之后在悉尼(au syd)地区创建的,或者其他地区已经转移到该系统,您将不得不通过该系统 使用基本身份验证初始获取令牌
curl -k -X POST \
--header "Authorization: Basic Yng6Yng=" \
--header "Content-Type: application/x-www-form-urlencoded" \
--header "Accept: application/json" \
--data-urlencode "grant_type=urn:ibm:params:oauth:grant-type:apikey" \
--data-urlencode "apikey={api_key}" \
"https://iam.bluemix.net/identity/token"
然后使用响应中的令牌进行进一步的API调用
curl -X GET \
--header "Authorization: Bearer {token}" \
"https://gateway.watsonplatform.net/discovery/api/v1/environments?version=2017-11-07"
请记住,您需要定期刷新令牌。我们在版本
1.3.3
中添加了对IAM的支持。始终确保您使用的是最新版本
使用IAM,您将用apikey
凭证字段中的IAM\u apikey
参数替换username
和password
import json
from watson_developer_cloud import NaturalLanguageUnderstandingV1
from watson_developer_cloud.natural_language_understanding_v1 \
import Features, EntitiesOptions, KeywordsOptions
natural_language_understanding = NaturalLanguageUnderstandingV1(
iam_apikey='the apikey value from your question',
url='https://gateway.watsonplatform.net/natural-language-understanding/api',
version='2018-03-16')
response = natural_language_understanding.analyze(
text='IBM is an American multinational technology company '
'headquartered in Armonk, New York, United States, '
'with operations in over 170 countries.',
features=Features(
entities=EntitiesOptions(
emotion=True,
sentiment=True,
limit=2),
keywords=KeywordsOptions(
emotion=True,
sentiment=True,
limit=2)))
print(json.dumps(response, indent=2))
非常感谢你!这很有帮助!非常感谢您的指导!非常感谢你!这真的很有帮助!