用Python访问Highrise的API?

0 投票
4 回答
932 浏览
提问于 2025-04-16 06:23

我怎么用Python访问37signals的Highrise API?我找到了PHP和Ruby的封装,但没有Python的。我现在自己在写,有没有人能给我一些关于如何解决Python中认证这个第一步的建议?

4 个回答

0

可以在这里查看如何进行基本的身份验证。另外,如果我没记错的话,urllib支持这种格式的链接:http://user:password@example.com

1

我刚好在解决这个问题时看到了你的提问。这里是我目前拼凑出来的东西。虽然看起来不太好,但它能工作。我对Pycurl不太熟悉,研究了一会儿后又回到了urllib2。Highrise使用的是基本认证,所以你不一定要用CURL,可以用urllib2。你只需要按照密码管理器的步骤来操作。输出的结果是一个很长的XML文件,里面包含所有公司或所有人的信息,这取决于你输入的URL。如果你只想要一个人的信息,可以用类似'http....../people/123.xml'或者'http....../people/123-fname-lname.xml'这样的链接(就像你在Highrise中查看某个联系人的时候,URL后面加了.xml)。

import ullib2    

PEOPLEurl = 'http://yourcompany.highrisehq.com/people.xml' #get all the people
# or 
COMPANYurl = 'http://yourcompany.highrisehq.com/company.xml' #get all companies

token = '12345abcd' #your token
password = 'X'

passmanager = urllib2.HTTPPasswordMgrWithDefaultRealm()
passmanager.add_password(None, PEOPLEurl, token, password)
authhandler = urllib2.HTTPBasicAuthHandler(passmanager)
opener = urllib2.build_opener(authhandler)
urllib2.install_opener(opener)
page = urllib2.urlopen(PEOPLEurl).read()

print page #this will dump out all the people contacts in highrise

这段代码的任何反馈或建议都很有帮助!

4

我正在为Python编写一个Highrise API的封装器。它使用Python对象来表示Highrise的每个类,工作方式和Django的ORM很相似:

>>> from pyrise import *
>>> Highrise.server('my-server')
>>> Highrise.auth('api-key-goes-here')
>>> p = Person()
>>> p.first_name = 'Joe'
>>> p.last_name = 'Schmoe'
>>> p.save()

你可以从GitHub获取源代码:https://github.com/feedmagnet/pyrise

或者可以从PyPI安装它:

$ sudo pip install pyrise

撰写回答