简体   繁体   English

如何在OpenCorporates REST API中使用访问令牌?

[英]How to use an access token with the OpenCorporates REST API?

I am trying to access opencorporates.com. 我正在尝试访问opencorporates.com。 The page says that this is authenticated version for the GET method http://api.opencorporates.com/companies/gb/00102498?api_token=ab123cd45 . 该页面说明这是GET方法的身份验证版本http://api.opencorporates.com/companies/gb/00102498?api_token=ab123cd45

This is my code to access the dataset. 这是我访问数据集的代码。 Here I am changing the jurisdiction code through the codes that I collected in a file. 在这里,我通过我在文件中收集的代码更改管辖区代码。 Even if I don't use the api token I am able to collect the same amount of data that I can with the api token. 即使我不使用api令牌,我也可以使用api令牌收集相同数量的数据。 Am I doing something wrong here? 我在这里做错了吗?

import urllib2
import json,os

f = open('codes','r')
for line in f.readlines():
   id = line.strip('\n')
   url = 'http://api.opencorporates.com/v0.2/companies/search?q=&jurisdiction_code={0}&per_page=26&current_status=Active&page={1}?api_token=ab123cd45' 
   i = 0
   directory = id
   os.makedirs(directory)
   while True:
      i += 1
      req = urllib2.Request(url.format(id, i))
      print url.format(id,i)
      try:
         response = urllib2.urlopen(url.format(id, i))
      except urllib2.HTTPError, e:
        break
      content = response.read()
      fo = str(i) + '.json'    
      OUTFILE = os.path.join(directory, fo)
      with open(OUTFILE, 'w') as f:
          f.write(content)

The end of your url looks like this: ?api_token=ab123cd45 , but it's already in the query string portion of the url, so it should look like: &api_token=ab123cd45 . 您的网址的结尾如下所示: ?api_token=ab123cd45 ,但它已经位于网址的查询字符串部分中,因此它应该如下所示: &api_token=ab123cd45 (Replace the ? with a & .) (用&替换?

You should consider using Requests when working with APIs. 在使用API​​时,您应该考虑使用请求

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何有效地使用 OpenCorporates Reconciliation API? - How to effectively use the OpenCorporates Reconciliation API? Flask Rest API - 如何在 python 请求中使用 Bearer API 令牌 - Flask Rest API - How to use Bearer API token in python requests 在测试REST API时如何使用令牌认证 - How to use token authentication while testing REST API 什么是基于令牌的身份验证,如何使用它访问 REST API GET 请求? NETSUITE API - What is Token Based Authentication, How to access REST API GET request using it? NETSUITE API 如何将接收到的(承载)访问令牌传递给生成的 REST 客户端以调用安全的 API-Gateway 端点 - How to pass received (bearer) access token to generated REST Client in order to invoke secured API-Gateway Endpoint 如何编写 Python 脚本以对 Azure DevOps REST API 进行身份验证并获取访问令牌? - How to write a python script to authenticate to Azure DevOps REST API and get the access token? 如何使用django rest框架APIClient测试登录后生成的oauth访问令牌? - How to use django rest framework APIClient to test oauth access token generated after login? Power BI 活动日志 REST API 获取访问令牌 - Power BI Activities Log REST API Get Access Token Django Rest API Djoser 刷新和访问令牌问题 - Django Rest API Djoser Refresh and Access Token Problem 使用 Python 检索 Power BI 的 Rest API 的访问令牌? - Using Python to retrieve access token for Power BI's Rest API?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM