スナックelve 本店

バツイチ40代女の日記です

ツイートしたり取得したり

cre8cre8.com
こちらを参考にトークンを取得して
qiita.com
でツイートできた。


取得するほうは

# 取得したキーとアクセストークンを設定する
from my_config import *
import twitter
auth = twitter.OAuth(ACCESS_TOKEN, ACCESS_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET_KEY)

t = twitter.Twitter(auth=auth)

tw=t.statuses.user_timeline(screen_name="test_hygienic",count=1)
format_json = json.dumps(tw, indent=4, separators=(',', ': '))
print(format_json)


1つのツイートにこんなに情報乗ってるんだなぁ~っと。

[
    {
        "created_at": "Fri May 18 22:17:57 +0000 2018",
        "id": 997602216683843584,
        "id_str": "997602216683843584",
        "text": "\u3054\u306b\u3087\u3054\u306b\u3087",
        "truncated": false,
        "entities": {
            "hashtags": [],
            "symbols": [],
            "user_mentions": [],
            "urls": []
        },
        "source": "<a href=\"https://elve.hatenadiary.jp/\" rel=\"nofollow\">DMGetterTest</a>",
        "in_reply_to_status_id": null,
        "in_reply_to_status_id_str": null,
        "in_reply_to_user_id": null,
        "in_reply_to_user_id_str": null,
        "in_reply_to_screen_name": null,
        "user": {
            "id": 16419703,
            "id_str": "16419703",
            "name": "elve",
            "screen_name": "test_hygienic",
            "location": "\u306f\u3066\u306a\u3061\u307b\u30fc",
            "description": "\u30d0\u30c4\u30a4\u30c140\u4ee3\u6d3e\u9063\u3002\u30de\u30eb\u30bb\u30a4\uff08\u5143\u592b\uff09\u3068\u66ae\u3089\u3059\u3002\u8cea\u554f\u7bb1\uff1ahttps://t.co/52hukbm3UP",
            "url": "https://t.co/8vbNrgE5vv",
            "entities": {
                "url": {
                    "urls": [
                        {
                            "url": "https://t.co/8vbNrgE5vv",
                            "expanded_url": "https://elve.hatenadiary.jp/",
                            "display_url": "elve.hatenadiary.jp",
                            "indices": [
                                0,
                                23
                            ]
                        }
                    ]
                },
                "description": {
                    "urls": [
                        {
                            "url": "https://t.co/52hukbm3UP",
                            "expanded_url": "https://peing.net/ja/elve",
                            "display_url": "peing.net/ja/elve",
                            "indices": [
                                27,
                                50
                            ]
                        }
                    ]
                }
            },
            "protected": false,
            "followers_count": 120,
            "friends_count": 124,
            "listed_count": 2,
            "created_at": "Tue Sep 23 14:37:24 +0000 2008",
            "favourites_count": 2521,
            "utc_offset": 32400,
            "time_zone": "Tokyo",
            "geo_enabled": false,
            "verified": false,
            "statuses_count": 13318,
            "lang": "ja",
            "contributors_enabled": false,
            "is_translator": false,
            "is_translation_enabled": false,
            "profile_background_color": "000000",
            "profile_background_image_url": "http://abs.twimg.com/images/themes/theme1/bg.png",
            "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme1/bg.png",
            "profile_background_tile": false,
            "profile_image_url": "http://pbs.twimg.com/profile_images/996640539570200577/C1cwC0X9_normal.jpg",
            "profile_image_url_https": "https://pbs.twimg.com/profile_images/996640539570200577/C1cwC0X9_normal.jpg",
            "profile_banner_url": "https://pbs.twimg.com/profile_banners/16419703/1525317214",
            "profile_link_color": "981CEB",
            "profile_sidebar_border_color": "000000",
            "profile_sidebar_fill_color": "000000",
            "profile_text_color": "000000",
            "profile_use_background_image": false,
            "has_extended_profile": false,
            "default_profile": false,
            "default_profile_image": false,
            "following": false,
            "follow_request_sent": false,
            "notifications": false,
            "translator_type": "none"
        },
        "geo": null,
        "coordinates": null,
        "place": null,
        "contributors": null,
        "is_quote_status": false,
        "retweet_count": 0,
        "favorite_count": 0,
        "favorited": false,
        "retweeted": false,
        "lang": "ja"
    }
]

で、だ。

from my_config import *
import twitter
import json

auth = twitter.OAuth(ACCESS_TOKEN, ACCESS_TOKEN_SECRET, CONSUMER_KEY, CONSUMER_SECRET_KEY)

t = twitter.Twitter(auth=auth)

dm=t.direct_messages.sent()
format_json = json.dumps(dm, indent=4, separators=(',', ': '))
print(format_json)

を実行すると

twitter.api.TwitterHTTPError: Twitter sent status 403 for URL: 1.1/direct_messages/sent.json

って言われちゃうの。ツイートは送受できるのになぜ!?

pypi.org
ひょっとしてサポートしてない?

旅は続く。

追記

f:id:elve:20180519082808p:plain
パーミッションとやらの設定を変えた。まだ取得できないが(´・ω:;.:...