Twitter开发
开发文档:https://developer.twitter.com/
the Twitter Developer Account Application 示例:https://wptweetboost.com/example-of-the-twitter-developer-account-application-process/
Help Center:https://help.twitter.com/en
Twitter Developers community(twitter 论坛):https://twittercommunity.com/
TwitterOAuth:https://twitteroauth.com/
The most popular PHP library for use with the Twitter OAuth REST API.
步骤:
1.申请a Twitter developer account:developer.twitter.com
2.创建Twitter Apps:https://apps.twitter.com/
原文:
As of July 2018, you must apply for a Twitter developer account and be approved before you may create new apps. Once approved, you will be able to create new apps from developer.twitter.com.
For the near future, you can continue to manage existing apps here on apps.twitter.com. However, we will soon retire this site and consolidate all developer tools, API access, and app management within the developer portal at developer.twitter.com. You will be able to access and manage existing apps through that portal when we retire this site.
Get started with Twitter APIs and tools:https://developer.twitter.com/en/apply-for-access.html
All new developers must apply for a developer account to access Twitter APIs. Once approved, you can begin to use our standard APIs and our new premium APIs.
More about restricted uses of the Twitter APIs:https://developer.twitter.com/en/developer-terms/more-on-restricted-use-cases
费用问题:
1. Create a Twitter app.
- Create a Twitter app with an approved developer account from the developer portal. If you are creating the app on behalf of your company, it is recommended you create the app with a corporate Twitter account. To apply for a developer account, click here.
- Enable “Read, Write and Access direct messages” on the permissions tab of your app page.
- On the "Keys and Access Tokens" tab, take note of your app's Consumer Key (API Key) and Consumer Token (API Secret).
- On the same tab, generate your app's Access Token and Access Token Secret. You will need these Access Tokens to register your webhook URL, which is where Twitter will send account events.
- If you are unfamiliar with Twitter Sign-in and how user contexts work with the Twitter API review Obtaining Access Tokens. As you add accounts for which to receive events, you will subscribe them using that account's access tokens.
- Take note of your app's numeric ID, as seen in the "Apps" page of the developer portal. When you apply for Account Activity API access, you'll need this app ID.
2. Get Account Activity API access
After creating a Twitter app, the next step is applying for Account Activity API access.
Premium
To access the Sandbox or Paid Premium Account Activity API tiers, you
need to set up a developer account. If you have not applied for a
developer account yet, please do so at the following link:
Once you have a developer account, then you are ready to set up
your access to the Premium Account Activity API. You will need a
registered
- Login and navigate to the "Dev Environments" page.
- Click 'Set up dev environment,' name your environment, and specify a Twitter app ID for the environment. The environment name you chose will replace the :env_name
token in our example premium endpoint URLs. For example, if you use the
'prod' environment name, your URL pattern would be
https://api.twitter.com/1.1/account_activity/all/prod/webhooks.
Enterprise
Those needing enterprise level access to more than 250 account
subscriptions and 3+ webhooks will need to submit an application at the
following link:
3. Develop webhook consumer app
Once you have received Account Activity API access, you need to develop, deploy and host a web app that will receive Twitter webhook events.
- Create a web app with a URL to use as your webhook to receive events. This is the endpoint deployed on your server to listen for incoming Twitter webhook events.
- The URI path is completely up to you. This example would be valid: https://mydomain.com/service/listen
- If you are listening for webhooks from a variety of sources, a common pattern is: https://mydomain.com/webhook/twitter
- Note that the specified URL can not include a port specification (https://mydomain.com:5000/NoWorkie).
- As described in our Securing Webhooks guide,
a first step is writing code that receives a Twitter Challenge Response
Check (CRC) GET request and responds with a properly formatted JSON
response. - Register your webhook URL. You will make a POST request to a /webhooks.json?url= endpoint.
When you make this request Twitter will issue a CRC request to your web
app. When a webhook is successfully registered, the response will
include a webhook id. This webhook id is needed later when making some requests to the Account Activity API. - Twitter will send account webhook events to the URL you registered.
Make sure your web app supports POST requests for incoming events. These
events will be encoded in JSON. See HERE for example webhook JSON payloads. - Once your web app is ready, the next step is adding accounts to
receive activities for. When adding (or deleting) accounts you will make
POST requests referencing the account id. See our guide on adding subscriptions for more information.
4. Validate setup
- To validate your app and webhook are configured correctly, favorite a
Tweet posted by one of the Twitter accounts your app is subscribed to.
You should receive afavorite_events
via a POST request to your webhook URL for each Favorite your subscribers receive.
中文资料:
英文资料
Stay up-to-date with Twitter developer platform news
advertiser api forums:https://twittercommunity.com/c/advertiser-api
Tutorials:Instructions and examples to help you get started
Spring.NET Social extension for Twitter
We are in the process of verifying the compatibility of the library with the Twitter Ads API.
Libraries built for HTTP with OAuth that should also work with Twitter
.NET
- DotNetOpenAuthby Andrew Arnott — an OpenID, OAuth and InfoCard library
- hammock2 by @danielcrenna — an HTTP API client supporting OAuth authentication.
- Spring.NET Socialby @SpringForNet — Spring.NET REST Client extension supporting OAuth authentication (docs) (examples)
Libraries built for the Twitter Platform
.NET
- LINQ2Twitter by @joemayo (examples)
- Spring.NET Social extension for Twitter by SpringSource — A Spring.NET Social extension with connection support and an API binding for Twitter.
- TweetSharp by @danielcrenna — A .net library for Twitter API access
- Tweetinvi maintained by Linvi — a Twitter .Net C# API which has for mission to simplify the development of application for Twitter in C#. The streaming API has been used on research projects and collected around 3.2 million Tweets a day. The Twitter API has been created to be easy to implement new functionality and currently provide access to most of the functionalities. (documentation)
- Crafted.Twitter by @martbrow — A caching compatible solution - with implementations for both ASP.Net Web Forms and MVC. Making it easy to include Tweets in your website.
Advertise on the Twitter network
Twitter’s Ads API endpoints provide developers a programmatic way to create and manage Twitter Ads campaigns. In addition, these endpoints provide a means to access features like Audiences, Creatives, Targeting, etc. Our tutorials page contains all the necessary information around the Ads entity hierarchy as well as a basic getting started guide.
Apply for Ads API access
In order to be able to use any of the Ads API endpoints, first create a Twitter app and apply for access here. Feel free to play around in our sandbox environment as well.
Check out our SDKs
The Python and Ruby SDKs provide a frictionless means to integrate with the Ads API directly in your application.
If you’re an expert on the Ads API feel free to help out others as well! Questions? See our developer forums.
工具:
Tweets
获取TwitterAPI keys
• 注册一个Twitter账号
• 到https://apps.twitter.com/登入twitter账号
• 点击“Create New App”,新建你自己的应用
• 填写应用信息表单, 然后点击“Create your Twitter application”生成你的twitter应用
• 在“keys and Access Tokens”界面, 点击“API keys”, 然后记录你的“API key” 和"API secret".
• 在“keys and Access Tokens”界面点击“Create my access token”, 记录你的"Access token" and "Access token secret".
这里我就不啰嗦一步一步截图了,按照上面一步一步做就行。但是只里面有一个坑,需要注意的:twitter在创建应用时,你的twitter账号一定要绑定你的手机,但是国内的手机运营商收不到验证码。这里好像可以用手机版twitter去绑定手机号(实测联通可以收到验证码,电信好像不可以,移动没试过)
使用TwitterAPI
这里我使用的twitter4J来调用twitter接口。
Twitter4j:http://twitter4j.org/en/index.html
在这里你下载twitter4j的zip包然后解压,将lib下面的这些jar包导入你的项目中。
twitter4j-core-source.jar包是自己打包的源码包,用来查看函数源码。
注:twitter4j的文档写的很不全,参考意义不是很大,你可以结合下载zip包中的examples文件夹中的例子还可以看twitter官网的Twitter REST APIs:https://dev.twitter.com/rest/public
twitter4j是的使用需要FQ代理,还有当你设置好以后,有可能会碰到链接拒绝(看你用的什么代理),因为eclipse默认走的是ipv6协议,具体解决方法可以参考我这篇文章:
http://blog.csdn.net/u013817676/article/details/51906754
Is possibile to know when applications that already exist will be definitively killed if not approved?
Isn’t possible to submit a new request of approval correcting what was wrong?
is it possible to get a direct contact to someone who manage it to understand what is wrong in a specific application?
We are not killing off any apps. You can read more about recent changes that we made related to this inbound here: Keeping things safe - new requirements affecting developers 58
At this point in time, it is not possible to submit a new request.
I am your direct contact at this point in time. Please review our policies 30 to better understand how your use case doesn’t fit.
If you have created a Twitter app via the apps.twitter.com platform before July 24th, then you will be able to manage that Twitter app via apps.twitter.com for the foreseeable future. If you have applied for a new developer account, you will also be able to edit manage that Twitter app via the developer portal as well. Since July 24th, you are required to have an approved developer account to create new apps.
If you are using one of the POST endpoints (Tweet, Retweet, Favorite, DM, Follow), you are currently rate limited based on the user level. On October 22nd (announcement about the delay), there will be new App level rate limits applied to those endpoints. These POST rate limits will be applied to all Twitter apps, regardless of when they were created.
Initial Setup
As a developer, there are several steps that you will need to take in order to begin using the Direct Messages services.
Step 1 - Create a Twitter app.
- Create an app on the "Apps" page of your approved developer account. If you are creating the app on behalf of your company, it is recommended you create the app with a corporate Twitter account.
- Enable “Read, Write and Access direct messages” on the permissions tab of your app page.
- On the "Keys and Tokens" tab, take note of your app's Consumer Key (API Key) and Consumer Token (API Secret).
- On the same tab, generate your app's Access Token and Access Token Secret. You will need these Access Tokens to register your webhook URL, which is where Twitter will send account events.
- If you are unfamiliar with Twitter Sign-in and how user contexts work with the Twitter API review Obtaining Access Tokens. As you add accounts for which to receive events, you will subscribe them using that account's access tokens.
- Take note of your app's numeric ID, as seen in the "Apps" page of the developer portal. When you apply for Account Activity API access, you'll need this app ID.
Step 2 - Get access to Account Activity API
After creating a Twitter app, the next step is applying for Account Activity API access.
Premium
To access the Sandbox or Paid Premium Account Activity API tiers, you need to set up a developer account. If you have not applied for a developer account yet, please do so at the following link:
Once you have a developer account, then you are ready to set up
your access to the Premium Account Activity API. You will need a Twitter
app to attach to your Account Activity API dev environment.
- Login and navigate to the Dev Environments page.
- Click 'Set up dev environment,' name your environment, and specify a Twitter app ID for the environment. The environment name you chose will replace the :env_name
token in our example premium endpoint URLs. For example, if you use the
'prod' environment name, your URL pattern would be
https://api.twitter.com/1.1/account_activity/all/prod/webhooks.
Step 3 - Develop webhook consumer app
If you would like to use a script with a visual dashboard to get set
up with your account activities, you should check out the Twitter
Dev-supported Account Activity Dashboard.
- Once you have received Account Activity API access, you need to
develop, deploy and host a web app that will receive Twitter webhook
events. - Create a web app with a URL to use as your webhook to receive
events. This is the endpoint deployed on your server to listen for
incoming Twitter webhook events.- The URI path is completely up to you. This example would be valid: https://mydomain.com/service/listen
- If you are listening for webhooks from a variety of sources, a common pattern is: https://mydomain.com/webhook/twitter
- Note that the specified URL can not include a port specification (https://mydomain.com:5000/NoWorkie).
- As described in our Securing Webhooks guide,
a first step is writing code that receives a Twitter Challenge Response
Check (CRC) GET request and responds with a properly formatted JSON
response. - Register your webhook URL. You will make a POST request to
a /webhooks.json?url= endpoint. When you make this request Twitter will
issue a CRC request to your web app. When a webhook is successfully
registered, the response will include a webhook id. This webhook id is
needed later when making some requests to the Account Activity API. - Twitter will send account webhook events to the URL you registered.
Make sure your web app supports POST requests for incoming events. These
events will be encoded in JSON. See HERE for example webhook JSON payloads. - Once your web app is ready, the next step is adding accounts to
receive activities for. When adding (or deleting) accounts you will make
POST requests referencing the account id. See our guide on adding subscriptions for more information. - To validate your app and webhook are configured correctly, favorite a
Tweet posted by one of the Twitter accounts your app is subscribed to.
You should receive a Favorite event via a POST request to your webhook
URL for each Favorite your subscribers receive.
Step 4 - Obtain User Permission
In order to perform write actions (create Tweets or messages) on
behalf of another account or to read private information from that
account, you will need to obtain access tokens. Access tokens provide
the user context when using the Twitter API.
Basic Definitions
- User - A Twitter @user. All write actions on the Twitter API require
the context of a user. Chatbots exist on Twitter accounts and are not
their own entity. The account the chatbot exists on is a user. Customers
interacting with the chatbot are also users. All messages sent on
Twitter are between two user entities. - App - A Twitter app is created in your approved developer account. An app is always owned by a single user. The app provides the base context for using the Twitter API.
How are tokens generated? Two scenarios:
- User owns the app / Single User - If the user is the owner of the
app, they can generate access tokens on the “Keys and Tokens” tab in an
app's "Details" section within the from the "Apps" page in the developer portal. Click the “Create” button on the bottom of the page. - User does not own the app / Multiple Users - If your app is going to
consume Account Activity events on behalf of multiple users, each user
must authenticate with your app to grant permission. To achieve this you
must have a web app that implements Twitter Sign-in.
At this point in the process, you should have all of the necessary information to set up an application in the developer portal,
perform the initial Challenge Response Check to secure your endpoint,
and obtain access tokens in order to publish content on both your own
application and on behalf of others who have given explicit permission.
Now let's take a look at the different endpoints we will be using in our
app.
Step 5 - Understanding how the endpoints fit together
To make experiences conversational we provide Direct Message data in
real time via webhooks which includes metadata about the features in
that experience. Additionally, we have REST endpoints to create
messages, get welcome messages and custom profile data, and manage these
features. Understanding the basic flow below will help you set up your
own app based on the sampleapp you cloned in step 3.
Direct Messages
- Data about Direct Messages (sent and received) is provided to
developers in real-time via their Account Activity API webhook setup- Register a webhook URL for the APP:
- API call to POST account_activity/all/:env_name/webhooks
- Developers can only register 1 URL per environment
- Developer will ask the user to authorize the app via Twitter Sign-in to generate valid access tokens.
- Add a new subscription (enable the app to receive Direct Messages on behalf of the user via the registered webhook)
- API call to POST account_activity/all/:env_name/subscriptions
- User needs to have a valid access token with the app (step 4)
- Validate your webhooks URL using the PUT account_activity/all/:env_name/webhooks endpoint
- Retrieve your webhook configuration using the GET account_activity/all/:env_name/webhooks endpoint
- Register a webhook URL for the APP:
- Get all Direct Messages sent and received in the last 30 days using the GET direct_messages/events/list endpoint
- Get a single Direct Message based on the ID using the GET direct_messages/events/show endpoint, there’s no time restriction on this endpoint
- Send a message using POST direct_messages/events/new (message_create)
- This endpoint is referenced in the send-direct-message script here
Welcome Messages
- Create a new welcome message using POST direct_messages/welcome_messages/new
- This endpoint is referenced in the create-welcome-message script here
- Create a new rule for welcome messages using POST direct_messages/welcome_messages/rules/new
- This endpoint is referenced in this script here
Subscription Endpoints
- Delete a subscriptions using DELETE account_activity/webhooks/:webhook_id/subscriptions
- This endpoint is referenced in this script
- Get your current webhook configuration using GET account_activity/webhooks
- This endpoint is referenced in this script
Debugging Tools
Below is a list of debugging tools you may find useful when building your application:
Twitter开发的更多相关文章
- Twitter开发2
There are different API families The standard (free) Twitter APIs consist of REST APIs and Streaming ...
- twitter接口开发
前一阵子研究了下twitter接口,发现网上的资料不是很多.遂花了些心血,终于有所收获~ 现在有时间赶紧整理出来便于自己以后查阅,也想帮助有困难的同学们.废话不多说,现在就以最简洁的方式开始了.注意: ...
- iOS:iOS开发非常全的三方库、插件等等
iOS开发非常全的三方库.插件等等 github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自git ...
- mui开发webapp(2)
前端开发APP,从HBuilder开始~ 序 通过 HTML5 开发移动App 时,会发现HTML5 很多能力不具备.为弥补HTML5 能力的不足,在W3C 中国的指导下成立了www.HTML5Plu ...
- 思考 ”前端开发人员都在关注的 GitHub 资源“
点这里 原文: 资源 免费的计算机编程类中文书籍 免费编程书籍 计算机科学论文 codeparkshare Python初学者书籍.视频.资料.社区推荐 Python资料汇总 app应用推荐 码农周刊 ...
- iOS开发--完整项目
完整项目 Phonetic Swift 写的一个 iOS 版的 Phonetic Contacts,功能很多,其中昵称功能非常实用,已在 GitHub 开源并上架 App Store v2ex – v ...
- 跨平台移动APP开发进阶(二)HTML5+、mui开发移动app教程
前端开发APP,从HBuilder开始~ 序 通过 HTML5 开发移动App 时,会发现HTML5 很多能力不具备.为弥补HTML5 能力的不足,在W3C 中国的指导下成立了www.HTML5Plu ...
- iOS开发之资料收集
github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自github:https://github ...
- AngularJS + CoffeeScript 前端开发环境配置详解
AngularJS 号称 '第一框架' ('The first framework') 确实是名不虚传.由其从jQuery中完全转入AngularJS后就有无法离开他的感觉了.虽然AngularJS的 ...
随机推荐
- hive 将一个分区表数据全部插入另外一个分区表
假如现在hive有个分区表A,分区字段为dt 需求是:需要将A表中的数据全部插入到分区表B中 具体步骤如下: 1.create B like A: 2.插入数据 set hive.exec.dynam ...
- Linux文件管理和编辑常用命令
Linux文件管理和编辑常用命令 mkdir 命令 功能说明 mkdir 命令用于创建一个目录,mkdir是make directory的缩写 格式: mkdir [选项] 目录名 mkdir 命令的 ...
- linux /etc/shadow--passwd/pam.d/system-auth文件详解
在linux操作系统中, /etc/passwd文件中的每个用户都有一个对应的记录行,记录着这个用户的一下基本属性.该文件对所有用户可读. 而/etc/shadow文件正如他的名字一样,他是pa ...
- java-web的mybatis的学习
idea开发必须是把Mapper文件与配置文件放到Resources标记的classpath目录下,eclips好像放到哪都行指定好路径就可以了, maven里面做好配置resources的路径,不然 ...
- vue 实现modal
本文只是作为练习弹出框,弹框内部的东西需要进行自定义添加,主要对更新,删除,新建 ,提示四种弹框进行实现,例子中只是简单的组件应用 Modal.vue文件 <template> <d ...
- python的类和对象
一.面向对象和面向过程 1.1面向过程的特点 优点是:极大的降低了写程序的复杂度,只需要顺着要执行的步骤,堆叠代码即可. 缺点是:一套流水线或者流程就是用来解决一个问题,代码牵一发而动全身. 1.2面 ...
- HTML(续)
1.有frame就无body,框架的noresize:设置框架大小不能改变.2.链接在框架中的应用target:有定为目标的功能.<a href = "链接源地址" targ ...
- SSM思路大总结(部门信息的显示和增删改查)
#ssm整合(部门管理) ##1.新建工程 1.新建maven工程 2.添加web.xml 3.添加tomcat运行环境 4.添加依赖jar包 spring-webmvc mysql commonse ...
- django field
name=models.CharField(max_length=30,unique=True,verbose_name='姓 名') birthday=models.DateField(bla ...
- MySQL PXC集群部署
安装 Percona-XtraDB-Cluster 架构: 三个节点: pxc_node_0 30.0.0.196 pxc_node_1 30.0.0.198 pxc_node_2 30.0.0.19 ...