0

I tried to use PHP Twitter API (users/show.json, version 1.1) to get the user details by passing username. It works great. My code is similar to this, using the library file.

But i want to know if it is possible to get the user data by passing website as the parameter (url, display_url or expanded_url). I have read the docs, but could not get any idea. Hope someone can help me.

EDIT: My updated code, used for testing:

<?php
require_once('TwitterAPIExchange.php');

$settings = array(
    'oauth_access_token' => "xxxxxx-xxxxxxxxxxxxxxxxxx",
    'oauth_access_token_secret' => "xxxxxxxxxxxxxxxxxxxxxxxx",
    'consumer_key' => "xxxxxxxxxxxxxxxxxxxxxxxx",
    'consumer_secret' => "xxxxxxxxxxxxxxxxxxxxxxxx"
);

$url = 'https://api.twitter.com/1.1/users/search.json';
$getfield = '?q=blessedsmiledentistry.com'; // Not working
//$getfield = '?q=stackoverflow.com'; // Working!

$requestMethod = 'GET';
$twitter = new TwitterAPIExchange($settings);
echo $twitter->setGetfield($getfield)
             ->buildOauth($url, $requestMethod)
             ->performRequest();

I see that, the search result for "stackoverflow.com" URL works fine, but i get an empty result with the URL: "blessedsmiledentistry.com". Not sure what i am doing wrong.

When i check the Twitter profiles related to my search terms, i did not find any major difference between them. Both profiles have name, handle, description, location, URL and joining date. But only the profile search for "stackoverflow.com" URL gives me a valid result. Is it because of the fact that "stackoverflow" is a verified Twitter account?

2 Twitter profiles

shasi kanth
  • 6,987
  • 24
  • 106
  • 158

1 Answers1

2

You can search for users with https://developer.twitter.com/en/docs/accounts-and-users/follow-search-get-users/api-reference/get-users-search.html

That will allow you to build up a search like:

/1.1/users/search.json?q=example.com

You will get back a selection of users who have example.com in their profile.

Terence Eden
  • 14,034
  • 3
  • 48
  • 89
  • Thanks for the answer. But when i tried it, i am getting the error like: Could not authenticate you... Code 32 – shasi kanth Feb 13 '19 at 05:53
  • Please post your full code. Do other api calls work? – Terence Eden Feb 13 '19 at 07:41
  • Yes, the other API calls work well, like /users/show.json.... I have updated my question with sample code. Hope you can check it. – shasi kanth Feb 15 '19 at 15:54
  • There are no Twitter results for that URL. Take a look on the normal Twitter website - https://twitter.com/search?f=users&vertical=default&q=blessedsmiledentistry.com&src=typd – Terence Eden Feb 15 '19 at 16:24
  • I agree with that. But i don't understand how the search term "stackoverflow.com" (a URL) is giving the result, where as the similar search term "blessedsmiledentistry.com" is not able to give a result. Please check my updated question with an image comparing both the Twitter profiles. Both look alike. – shasi kanth Feb 18 '19 at 13:33