Skip to main content

Python library for mixi Graph API

Project description

概要

mixi Graph API を Python から簡単に使えるようにするためのライブラリです。

インストール方法

easy_install を使ってインストールします。 依存ライブラリの MultipartPostHandler も自動的にインストールされます。

# easy_install strippers.mixi

サポートしているAPI

現在このライブラリがサポートしている mixi Graph API は以下の通りです。

People API

READ_PROFILE (r_profile) スコープ

  • 友人一覧の取得
    • get_friends(group_id=’@friends’, sort_by=None, sort_order=’ascending’, count=20, start_index=0)

Voice API

READ_VOICE (r_voice) スコープ

WRITE_VOICE (w_voice) スコープ

Message API

READ_MESSAGE (r_message) スコープ

WRITE_MESSAGE (w_message) スコープ

Check API

WRITE_SHARE (r_share) スコープ

  • mixiチェックの投稿
    • share(key, title, url, image=None, pc_url=None, smartphone_url=None, mobile_url=None, description=None, comment=None, visibility=’self’)

使用方法

MixiGraphAPI オブジェクトの初期化

>>> from strippers.mixi import MixiGraphAPI, WRITE_VOICE, DEVICE_PC
>>>
>>> # mixi サービス登録情報を定義
>>> consumer_key = 'xxxxxxxxxxxxxxxxxxxx'
>>> consumer_secret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
>>> redirect_uri = 'http://www.example.com/mixi/authorized'
>>>
>>> # 使用する API のスコープを指定
>>> scopes = [WRITE_VOICE]
>>>
>>> # (1) MixiGraphAPI オブジェクトを生成
>>> api = MixiGraphAPI(consumer_key, consumer_secret, scopes)
>>>
>>> # (2) ユーザ認可用 URL を取得
>>> api.get_auth_url(device=DEVICE_PC)
'https://mixi.jp/connect_authorize.pl?scope=w_voice&response_type=code&client_id=xxxxxxxxxxxxxxxxxxxx&display=pc'

>>> # (3) 上の URL にアクセスして[同意する]と、サービス登録した redirect_uri に
>>> # code パラメータ付きでリダイレクトされてきます。
>>> # この code パラメータを利用します。
>>> code = '5fbf8d9e55f0df0deff68cd4a8500701b3fe6baa'
>>>
>>> # (4) MixiGraphAPI オブジェクトを初期化
>>> api.initialize(code, redirect_uri)
>>>
>>> # 認可ユーザのアクセストークンとリフレッシュトークンを取得
>>> access_token, refresh_token = api.tokens

MixiGraphAPI オブジェクトを初期化すると、各 API メソッドを実行できるようになります。

ユーザのアクセストークンとリフレッシュトークンが予め分かっている場合は、上記(1)~(4)の MixiGraphAPI オブジェクトの初期化処理は要らず、次のようにアクセストークンとリフレッシュトークンを引数に渡して MixiGraphAPI オブジェクトを生成するだけで済みます。

>>> api = MixiGraphAPI(consumer_key, consumer_secret, scopes, access_token, refresh_token)

つぶやきの投稿

>>> status = api.update_status('投稿なう')
>>>
>>> # 上のつぶやきを削除します
>>> api.delete_status(status['id'])

フォト付きでつぶやきを投稿するには、画像ファイルのファイルパス、または「http(s)://」で始まる URL を第2引数に渡します。

>>> api.update_status('フォト投稿なう', '/path/to/picture.jpg')
>>>
>>> # フォトだけの投稿も可能
>>> api.update_status(photo='/path/to/picture.jpg')

トークンの有効期限切れ

アクセストークン、リフレッシュトークンそれぞれに有効期限があります。アクセストークンの有効期限は約15分ですが、リフレッシュトークンが有効期限内は MixiGraphAPI オブジェクト内部で自動的に再取得(リフレッシュ)します。

リフレッシュトークンの有効期限は約6時間(ユーザ認可時に「常に同意する」のチェックを入れていれば約3ヶ月間)です。リフレッシュトークンが期限切れになった場合は、MixiGraphAPI オブジェクトの初期化処理が必要になります。つまり、再度ユーザ認可を行います。

>>> from strippers.mixi import ExpiredTokenError
>>>
>>> try:
>>>     api.update_status('リフレッシュトークン期限切れの場合')
>>> except ExpiredTokenError:
>>>     auth_url = api.get_auth_url(device=DEVICE_PC)
>>>     # auth_url にアクセスしてユーザ認可処理...

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

strippers.mixi-1.0b4.tar.gz (11.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

strippers.mixi-1.0b4-py2.7.egg (24.6 kB view details)

Uploaded Egg

File details

Details for the file strippers.mixi-1.0b4.tar.gz.

File metadata

File hashes

Hashes for strippers.mixi-1.0b4.tar.gz
Algorithm Hash digest
SHA256 874e117bd352d271ef7f899736446a86a5fdb033694e2e95e805e98e2cd4aa1d
MD5 14e2ae4074bf67312561d90c032db97c
BLAKE2b-256 b7cd1d529df924609e18ff84ec6583b02c4d29b57714448ca3bdabcbc6b2af02

See more details on using hashes here.

File details

Details for the file strippers.mixi-1.0b4-py2.7.egg.

File metadata

File hashes

Hashes for strippers.mixi-1.0b4-py2.7.egg
Algorithm Hash digest
SHA256 d111cbba57f7016db83cd07aac37e9172e2f4f0e5d4ba807be2d97e05af53f27
MD5 161f115c117227dadc20988813d7b7c8
BLAKE2b-256 a9c403e2610c4318593f54193cdbb506d8a2f3dff5ff82f6f37f37db5c18ac7d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page