Home > Backend Development > PHP Tutorial > How to Retrieve a User's Timeline with the Twitter API v1.1 Using Minimal PHP Code?

How to Retrieve a User's Timeline with the Twitter API v1.1 Using Minimal PHP Code?

DDD
Release: 2024-12-29 16:58:11
Original
654 people have browsed it

How to Retrieve a User's Timeline with the Twitter API v1.1 Using Minimal PHP Code?

Simplest PHP Example for Retrieving user_timeline with Twitter API Version 1.1

The Twitter API version 1.0 is now retired, making the code provided in the question outdated. To retrieve the user_timeline (recent statuses) with the least code possible, follow these steps:

Setup

  1. Create a Developer Account: Create an account on the Twitter Developer site.
  2. Create an Application: On the Developer site, create a new application to obtain your unique API keys.
  3. Generate Access Tokens: Click "Create my access token" on your application page to obtain the necessary tokens.
  4. Update Access Level: Ensure your application has Read & Write access by navigating to "Settings" within your application.

Implementation

Next, utilize the following PHP class and code:

require_once('TwitterAPIExchange.php');

$settings = [
    'oauth_access_token' => 'YOUR_ACCESS_TOKEN',
    'oauth_access_token_secret' => 'YOUR_ACCESS_TOKEN_SECRET',
    'consumer_key' => 'YOUR_CONSUMER_KEY',
    'consumer_secret' => 'YOUR_CONSUMER_SECRET'
];

$url = 'https://api.twitter.com/1.1/statuses/user_timeline.json';
$requestMethod = 'GET';

$twitter = new TwitterAPIExchange($settings);
echo $twitter->buildOauth($url, $requestMethod)->performRequest();
Copy after login

Response

The response from the Twitter API will be displayed as an array of recent user statuses.

The above is the detailed content of How to Retrieve a User's Timeline with the Twitter API v1.1 Using Minimal PHP Code?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template