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/

身份认证:https://developer.twitter.com/en/docs/basics/authentication/overview/3-legged-oauth

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

费用问题:

Twitter开发

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

  1. Login and navigate to the "Dev Environments" page.
  2. 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:

Apply for Enterprise acce

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 a favorite_events via a POST request to your webhook URL for each Favorite your subscribers receive.

中文资料:

  如何在Twitter开发者平台上注册自己的应用

  瞎折腾之Webhooks

  twitter APi的使用与twitter数据的应用

  Twitter API中文文档

  

英文资料

  Twitter Apps

  ads api application

  twitter engineering

  twitter marketing

  Stay up-to-date with Twitter developer platform news

  understanding-discourse-trust-levels

  Programmatically create and manage Twitter Ads campaigns.

  
 
 

  Sorting

  API reference index

  products-overview

  Twitter Ads API

  advertiser api forums:https://twittercommunity.com/c/advertiser-api

  Tutorials:Instructions and examples to help you get started

  Twitter Dev in github

    https://github.com/twitterdev

  data-ads-sample

  twitter-python-ads-sdk

  twitter-ruby-ads-sdk

  TwitterKitSample

  analytics-tag-check

  Twitter libraries

    LinqToTwitter

      LinqToTwitter

    Spring.NET Social extension for Twitter

    tweetinvi

      We are in the process of verifying the compatibility of the library with the Twitter Ads API.

    Crafted.Twitter

  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.

  Tweet objects

  Introduction to Tweet JSON

  

工具:

  Using Twurl

  

Tweets

  Post, retrieve and engage with Tweets

  timezones

  Rate Limiting

  Tweet objects

  

  

获取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

Application not approved

  1. Is possibile to know when applications that already exist will be definitively killed if not approved?

  2. Isn’t possible to submit a new request of approval correcting what was wrong?

  3. is it possible to get a direct contact to someone who manage it to understand what is wrong in a specific application?

  1. 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

  2. At this point in time, it is not possible to submit a new request.

  3. 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:

Apply for developer account

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.

  1. Login and navigate to the Dev Environments page.
  2. 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:

  1. 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.
  2. 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

Welcome Messages

Subscription Endpoints

Debugging Tools

Below is a list of debugging tools you may find useful when building your application:

    • Postman - Build mock requests
    • Ngrok - Test the code on your local machine
    • Runscope - Enables a developer to see how the flow of the API works
上一篇:Hadoop自定义分组Group


下一篇:github进行fetch更新代码