Updated June 1, 2015
API access to update this setting has been restricted to whitelist access only. If your app requires access, you can apply for “can_dm” access using this form. The setting can still be accessed by the user through their settings on twitter.com.
Today we’re updating the Direct Messages experience on the Twitter iPhone app, Android app and Twitter.com to enable users to create private conversations on Twitter more easily. More specifically, we are giving users the option to receive DMs from anyone, and to always be able to reply once a message is received.
We believe these features are useful for a variety of use cases. Journalists and newsrooms can open up a more private, direct relationship to their viewers and constituencies. Likewise, brands can offer their customers faster and more responsive support.
These changes will be reflected via the API, as well. When sending DMs, the API will simply respect the user’s setting of accept/don’t accept DMs from anyone.
A few specific behaviors in the API to note, for advanced developers:
-
The account settings object has an allow_dms_from field which
indicates who can DM a user, either in a private one-on-one thread or
in a group thread. Possible values include “following” (only users
you are following are allowed to DM you) and “all” (allow any user
on Twitter to DM you).
-
The API endpoint /account/settings.json allows the logged in user to
set the values for allow_dms_from. This endpoint returns the
current values as well. Editing this permission requires the “Read,
Write and Access direct messages” permission in you app. An example request and response are below.
-
To prevent DMs from a particular user, you must block that user. This
removes the user-to-user association on our side, preventing future
DMs. A following un-block will still respect the no-DM state.un-block
will still respect the no-DM state.
POST Request:
https://api.twitter.com/1.1/account/settings.json?allow_dms_from=all
HTTP Response:
{
"sleep_time": {
"end_time": null,
"enabled": false,
"start_time": null
},
"use_cookie_personalization": true,
"trend_location": [{
"name": "San Francisco",
"placeType": {
"name": "Town",
"code": 7
},{
"woeid": 2487956,
"country": "United States",
"url": "http://where.yahooapis.com/v1/place/2487956",
"countryCode": "US",
"parentid": 23424977
}],
"language": "en",
"discoverable_by_email": true,
"always_use_https": true,
"protected": false,
"geo_enabled": true,
"show_all_inline_media": false,
"screen_name": "oauth_dancer",
"allow_dms_from": "all"
}