Browse Source

catch non-expanded profile URLs

apparently some people's profile URLs don't get t.co'd
pull/39/head
Aaron Parecki 4 years ago
parent
commit
876d4696fb
3 changed files with 207 additions and 3 deletions
  1. +8
    -3
      lib/Formats/Twitter.php
  2. +8
    -0
      tests/TwitterTest.php
  3. +191
    -0
      tests/data/api.twitter.com/791704641046052864.json

+ 8
- 3
lib/Formats/Twitter.php View File

@ -178,10 +178,15 @@ class Twitter {
else
$author['name'] = $profile->screen_name;
if($profile->url)
$author['url'] = $profile->entities->url->urls[0]->expanded_url;
else
if($profile->url) {
if($profile->entities->url->urls[0]->expanded_url)
$author['url'] = $profile->entities->url->urls[0]->expanded_url;
else
$author['url'] = $profile->entities->url->urls[0]->url;
}
else {
$author['url'] = 'https://twitter.com/' . $profile->screen_name;
}
$author['photo'] = $profile->profile_image_url_https;

+ 8
- 0
tests/TwitterTest.php View File

@ -38,6 +38,14 @@ class TwitterTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('https://pbs.twimg.com/profile_images/638125135904436224/qd_d94Qn_normal.jpg', $data['data']['author']['photo']);
}
public function testProfileWithNonExpandedURL() {
list($url, $json) = $this->loadTweet('791704641046052864');
$data = $this->parse(['url' => $url, 'json' => $json]);
$this->assertEquals('http://agiletortoise.com', $data['data']['author']['url']);
}
public function testBasicTestStuff() {
list($url, $json) = $this->loadTweet('818913630569664512');

+ 191
- 0
tests/data/api.twitter.com/791704641046052864.json View File

@ -0,0 +1,191 @@
{
"created_at": "Thu Oct 27 18:14:30 +0000 2016",
"id": 791704641046052864,
"id_str": "791704641046052864",
"full_text": "Can’t wait. https://t.co/CR7Feah4q6",
"truncated": false,
"display_text_range": [
0,
11
],
"entities": {
"hashtags": [
],
"symbols": [
],
"user_mentions": [
],
"urls": [
],
"media": [
{
"id": 791704634058387456,
"id_str": "791704634058387456",
"indices": [
12,
35
],
"media_url": "http://pbs.twimg.com/media/CvyzK4gUsAACJWa.jpg",
"media_url_https": "https://pbs.twimg.com/media/CvyzK4gUsAACJWa.jpg",
"url": "https://t.co/CR7Feah4q6",
"display_url": "pic.twitter.com/CR7Feah4q6",
"expanded_url": "https://twitter.com/agiletortoise/status/791704641046052864/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 680,
"h": 321,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"medium": {
"w": 929,
"h": 439,
"resize": "fit"
},
"large": {
"w": 929,
"h": 439,
"resize": "fit"
}
}
}
]
},
"extended_entities": {
"media": [
{
"id": 791704634058387456,
"id_str": "791704634058387456",
"indices": [
12,
35
],
"media_url": "http://pbs.twimg.com/media/CvyzK4gUsAACJWa.jpg",
"media_url_https": "https://pbs.twimg.com/media/CvyzK4gUsAACJWa.jpg",
"url": "https://t.co/CR7Feah4q6",
"display_url": "pic.twitter.com/CR7Feah4q6",
"expanded_url": "https://twitter.com/agiletortoise/status/791704641046052864/photo/1",
"type": "photo",
"sizes": {
"small": {
"w": 680,
"h": 321,
"resize": "fit"
},
"thumb": {
"w": 150,
"h": 150,
"resize": "crop"
},
"medium": {
"w": 929,
"h": 439,
"resize": "fit"
},
"large": {
"w": 929,
"h": 439,
"resize": "fit"
}
}
}
]
},
"source": "<a href=\"http://tapbots.com/software/tweetbot/mac\" rel=\"nofollow\">Tweetbot for Mac</a>",
"in_reply_to_status_id": null,
"in_reply_to_status_id_str": null,
"in_reply_to_user_id": null,
"in_reply_to_user_id_str": null,
"in_reply_to_screen_name": null,
"user": {
"id": 6152112,
"id_str": "6152112",
"name": "Greg Pierce",
"screen_name": "agiletortoise",
"location": "N Richland Hills, TX",
"description": "I make @draftsapp, @interact_app, @dicedapp. I wrote the @xcallbackurl spec. This is my personal account, visit https://t.co/LJaFQkB5wy for support.",
"url": "http://agiletortoise.com",
"entities": {
"url": {
"urls": [
{
"url": "http://agiletortoise.com",
"expanded_url": null,
"indices": [
0,
24
]
}
]
},
"description": {
"urls": [
{
"url": "https://t.co/LJaFQkB5wy",
"expanded_url": "http://help.agiletortoise.com",
"display_url": "help.agiletortoise.com",
"indices": [
112,
135
]
}
]
}
},
"protected": false,
"followers_count": 5536,
"friends_count": 359,
"listed_count": 476,
"created_at": "Sat May 19 02:34:45 +0000 2007",
"favourites_count": 3604,
"utc_offset": -21600,
"time_zone": "Central Time (US & Canada)",
"geo_enabled": false,
"verified": false,
"statuses_count": 19912,
"lang": "en",
"contributors_enabled": false,
"is_translator": false,
"is_translation_enabled": false,
"profile_background_color": "706E65",
"profile_background_image_url": "http://pbs.twimg.com/profile_background_images/2571674/images.jpeg",
"profile_background_image_url_https": "https://pbs.twimg.com/profile_background_images/2571674/images.jpeg",
"profile_background_tile": false,
"profile_image_url": "http://pbs.twimg.com/profile_images/718519462656237568/t8hpFYGa_normal.jpg",
"profile_image_url_https": "https://pbs.twimg.com/profile_images/718519462656237568/t8hpFYGa_normal.jpg",
"profile_banner_url": "https://pbs.twimg.com/profile_banners/6152112/1476386061",
"profile_link_color": "071E7A",
"profile_sidebar_border_color": "FFFFFF",
"profile_sidebar_fill_color": "EBEBEB",
"profile_text_color": "000000",
"profile_use_background_image": false,
"has_extended_profile": true,
"default_profile": false,
"default_profile_image": false,
"following": false,
"follow_request_sent": false,
"notifications": false,
"translator_type": "none"
},
"geo": null,
"coordinates": null,
"place": null,
"contributors": null,
"is_quote_status": false,
"retweet_count": 1245,
"favorite_count": 1429,
"favorited": false,
"retweeted": true,
"possibly_sensitive": false,
"possibly_sensitive_appealable": false,
"lang": "en"
}

Loading…
Cancel
Save