Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ibm cloud 如何查找IBMAPI的用户id和密码?_Ibm Cloud - Fatal编程技术网

Ibm cloud 如何查找IBMAPI的用户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

我是IBMAPI的初学者。我刚刚启动了一个IBM自然语言理解服务。然而,我得到的是API密钥,而不是用户id和密码。像这样:

{
  "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请求承载令牌。

这在实例的中有详细说明

  • 单击“显示”查看您的凭据

  • 复制用户名、密码和url值

  • 重要提示:本教程使用服务实例凭据 向自然语言理解服务进行身份验证。在某些方面 区域、新服务实例使用IBM®云标识和 用于身份验证的访问管理(IAM)令牌。认证人 使用适合您所在区域和服务实例的方法

    他们提到了不同地区的不同身份验证类型,但他们并没有真正指定哪个地区使用哪种类型

    报告中指出了这一点

    2018年5月29日

    该服务现在支持服务的新API身份验证过程 在悉尼创建的实例(au syd)。IBM®云正在进行 迁移到基于令牌的身份和访问管理(IAM) 认证。IAM使用访问令牌而不是服务凭据 用于使用服务进行身份验证

    截至5月29日,只有在悉尼新创建的实例(au syd)使用不同的身份验证方法。除了按时间顺序浏览发行说明外,我不确定是否还有更好的方法找到这些信息


    因此,如果您的实例是在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))
    

    非常感谢你!这很有帮助!非常感谢您的指导!非常感谢你!这真的很有帮助!