Python 正在尝试调用AlchemyLanguage API

Python 正在尝试调用AlchemyLanguage API,python,api,ibm-cloud,alchemyapi,Python,Api,Ibm Cloud,Alchemyapi,我已经编写了用Python调用Bluemix的AlchemyLanguage API的代码。我需要关键字和实体,但它只显示文本文件的第一个关键字和第一个实体。我哪里做错了 import requests import urllib import urllib2 def call_alchemy_api(text, API_KEY): payload = {'outputMode':'json','extract':'entities,keywords','sentim

我已经编写了用Python调用Bluemix的AlchemyLanguage API的代码。我需要关键字和实体,但它只显示文本文件的第一个关键字和第一个实体。我哪里做错了

import requests    
import urllib    
import urllib2

def call_alchemy_api(text, API_KEY):

    payload = {'outputMode':'json','extract':'entities,keywords','sentiment':'1','maxRetrieve':'1', 'url':'https://www.ibm.com/us-en/'}
    payload['apikey'] = API_KEY
    encoded_text = urllib.quote_plus(text)
    payload['text'] = text
    data = urllib.urlencode(payload)
    url = 'https://gateway-a.watsonplatform.net/calls/text/TextGetCombinedData'
    req = urllib2.Request(url, data)
    response = urllib2.urlopen(req)
    return response

if __name__ == "__main__":

    api_key = 'xxxxxxxxxxxxxxxxxxxxxmyapi'
    f = open('in0.txt','r')
    text = f.read()

    print text
    response = call_alchemy_api(text, api_key)
    print response.read()

更改
maxRetrieve
关键字的值

示例:

payload = {'outputMode':'json','extract':'entities,keywords','sentiment':'1','maxRetrieve':'3', 'url':'https://www.ibm.com/us-en/'}
API链接:

payload = {'outputMode':'json','extract':'entities,keywords','sentiment':'1','maxRetrieve':'3', 'url':'https://www.ibm.com/us-en/'}