I am trying to get twitter direct message list in php

i am trying to get twitter direct message list in php

i was until now only able to get tweets retweets but i dont know how do i show direct message in php
this is the code i was able to get tweets only now how do i convert it itos how direct message
$url = “https://api.twitter.com/1.1/statuses/user_timeline.json”;
$requestMethod = “GET”;
if (isset($GET[‘user’])) {$user = preg_replace("/[^A-Za-z0-9]/", ‘’, $_GET[‘user’]);} else {$user = “trtworld”;}
if (isset($_GET[‘count’]) && is_numeric($_GET[‘count’]) {$count = $_GET[‘count’];} else {$count = 20;}
$getfield = “?screen_name=$user&count=$count&tweet_mode=extended”;
$twitter = new TwitterAPIExchange($settings);
$string = json_decode($twitter->setGetfield($getfield)
->buildOauth($url, $requestMethod)
->performRequest(),$assoc = TRUE);
if(array_key_exists(“errors”, $string)) {echo “

Sorry, there was a problem.

Twitter returned the following error message:


foreach($string as $items)
echo “Time and Date of Tweet: “.$items[‘created_at’].”
echo “Tweet: “. $items[‘full_text’].”
echo “Tweeted by: “. $items[‘user’][‘name’].”
echo “Screen name: “. $items[‘user’][‘screen_name’].”
echo “Followers: “. $items[‘user’][‘followers_count’].”
echo “Friends: “. $items[‘user’][‘friends_count’].”
echo “Listed: “. $items[‘user’][‘listed_count’].”


My suggestion is to go to this link Direct Message API features as they have a tutorial on how to set it up. I also have a tip use your console to see the Twitter’s API response (when you get it working) as it will be as simple as copying and editing the line in your own javascript.

That’s what I did with my Nasa javascript file:

'use strict';

/* I didn't show it even though it's a public key for NASA's APIs:
const nasaAPI = "PRIVATE";
//const nasaAPI = "PRIVATE";

const nasaUrl = "https://api.nasa.gov/planetary/apod?api_key=";

const nasaImage = document.querySelector('#apod');
const nasaImageHD = document.querySelector('#apodHD');
const nasaInfo = document.querySelector('#nasaInfo');

const requestUrl = nasaUrl + nasaAPI;
const nasaVideo = document.querySelector('#video');

/* Success function utilizing FETCH */
const nasaUISuccess = function (parsedData) {
    console.log('Nasa Data', parsedData);
    if (parsedData.media_type === "video") {
        nasaImage.style.display = "none";
        nasaVideo.setAttribute('src', `${parsedData.url}&autoplay=1`);

    } else {
        nasaVideo.style.display = "none";
        nasaImage.setAttribute('src', parsedData.url);
        nasaImageHD.setAttribute('href', parsedData.hdurl);

    nasaImage.setAttribute('title', parsedData.title);
    nasaInfo.textContent = parsedData.explanation;

/* If nasa API did not load correctly */
const nasaUIError = function (error) {
    console.log("Database Table did not load", error);
    nasaVideo.style.display = "none";
    nasaImage.setAttribute('src', 'assets/images/Orion212_Volskiy_960.jpg');
    nasaImageHD.setAttribute('href', 'assets/images/Orion212_Volskiy_5574.jpg');
    nasaImage.setAttribute('title', 'A 212-Hour Exposure of Orio');
    nasaInfo.textContent = "The constellation of Orion is much more than three stars in a row. It is a direction in space that is rich with impressive nebulas. To better appreciate this well-known swath of sky, an extremely long exposure was taken over many clear nights in 2013 and 2014. After 212 hours of camera time and an additional year of processing, the featured 1400-exposure collage spanning over 40 times the angular diameter of the Moon emerged. Of the many interesting details that have become visible, one that particularly draws the eye is Barnard's Loop, the bright red circular filament arcing down from the middle. The Rosette Nebula is not the giant red nebula near the top of the image -- that is a larger but lesser known nebula known as Lambda Orionis. The Rosette Nebula is visible, though: it is the red and white nebula on the upper left. The bright orange star just above the frame center is Betelgeuse, while the bright blue star on the lower right is Rigel. Other famous nebulas visible include the Witch Head Nebula, the Flame Nebula, the Fox Fur Nebula, and, if you know just where to look, the comparatively small Horsehead Nebula. About those famous three stars that cross the belt of Orion the Hunter -- in this busy frame they can be hard to locate, but a discerning eye will find them just below and to the right of the image center.";


 * Throw error response if something is wrong: 
const handleErrors = function (response) {
    if (!response.ok) {
        throw (response.status + ' : ' + response.statusText);
    return response.json();

/* create FETCH request */
const createRequest = function (url, succeed, fail) {
            .then((response) => handleErrors(response))
            .then((data) => succeed(data))
            .catch((error) => fail(error));

createRequest(requestUrl, nasaUISuccess, nasaUIError);

//const nasaUrl = "https://api.nasa.gov/mars-photos/api/v1/rovers/Opportunity/photos?sol=1&camera=PANCAM&api_key=";
//const nasaUrl = "https://api.nasa.gov/mars-photos/api/v1/manifests/opportunity?api_key=";

I used Vanilla JS, but the principle is the same.

Sponsor our Newsletter | Privacy Policy | Terms of Service