Browse Source

drop extra request for profiles when fetching instagram photos

pull/94/head
Aaron Parecki 5 years ago
parent
commit
f381cf30cf
No known key found for this signature in database GPG Key ID: 276C2817346D6056
2 changed files with 30 additions and 24 deletions
  1. +15
    -11
      lib/XRay/Formats/Instagram.php
  2. +15
    -13
      tests/InstagramTest.php

+ 15
- 11
lib/XRay/Formats/Instagram.php View File

@ -135,13 +135,18 @@ class Instagram extends Format {
$profiles = []; $profiles = [];
if(!$profile) { if(!$profile) {
// Fetch profile info for this user
$username = $photoData['owner']['username'];
$profile = self::_getInstagramProfile($username, $http);
if($profile) {
$entry['author'] = self::_buildHCardFromInstagramProfile($profile);
$profiles[] = $profile;
if(isset($photoData['owner'])) {
// Get profile info from the page
$entry['author'] = self::_buildHCardFromInstagramProfile($photoData['owner']);
} }
// 2019-10-13 disabling this fetch because profile fetches are severely rate limited now
// // Fetch profile info for this user
// $username = $photoData['owner']['username'];
// $profile = self::_getInstagramProfile($username, $http);
// if($profile) {
// $entry['author'] = self::_buildHCardFromInstagramProfile($profile);
// $profiles[] = $profile;
// }
} else { } else {
$entry['author'] = self::_buildHCardFromInstagramProfile($profile); $entry['author'] = self::_buildHCardFromInstagramProfile($profile);
$profiles[] = $profile; $profiles[] = $profile;
@ -285,14 +290,13 @@ class Instagram extends Format {
else else
$author['name'] = $profile['username']; $author['name'] = $profile['username'];
if(isset($profile['external_url']) && $profile['external_url'])
$author['url'] = $profile['external_url'];
else
$author['url'] = 'https://www.instagram.com/' . $profile['username'];
$author['nickname'] = $profile['username'];
$author['url'] = 'https://www.instagram.com/' . $profile['username'] . '/';
if(isset($profile['profile_pic_url_hd'])) if(isset($profile['profile_pic_url_hd']))
$author['photo'] = $profile['profile_pic_url_hd']; $author['photo'] = $profile['profile_pic_url_hd'];
else
elseif(isset($profile['profile_pic_url']))
$author['photo'] = $profile['profile_pic_url']; $author['photo'] = $profile['profile_pic_url'];
if(isset($profile['biography'])) if(isset($profile['biography']))

+ 15
- 13
tests/InstagramTest.php View File

@ -37,9 +37,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('Kind of crazy to see the whole year laid out like this. #planning #2017', $data['data']['content']['text']); $this->assertEquals('Kind of crazy to see the whole year laid out like this. #planning #2017', $data['data']['content']['text']);
$this->assertEquals(1, count($data['data']['photo'])); $this->assertEquals(1, count($data['data']['photo']));
$this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/vp/af9471f885e6197478d71807a7cbf297/5CBA6E5F/t51.2885-15/e35/15803256_1832278043695907_4846092951052353536_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net'], $data['data']['photo']); $this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/vp/af9471f885e6197478d71807a7cbf297/5CBA6E5F/t51.2885-15/e35/15803256_1832278043695907_4846092951052353536_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net'], $data['data']['photo']);
$this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
$this->assertEquals('https://www.instagram.com/aaronpk/', $data['data']['author']['url']);
$this->assertEquals('Aaron Parecki', $data['data']['author']['name']); $this->assertEquals('Aaron Parecki', $data['data']['author']['name']);
$this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/45aee453740a714bf408f8947f89da8e/5CCB4B8E/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['author']['photo']);
$this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/a2909937316893f18760f1077ca88fa1/5CBB520A/t51.2885-19/s150x150/14240576_268350536897085_1129715662_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['author']['photo']);
$this->assertArrayNotHasKey('meta', $data['data']); // make sure this does not include alt text (autogenerated placeholder from instagram) $this->assertArrayNotHasKey('meta', $data['data']); // make sure this does not include alt text (autogenerated placeholder from instagram)
} }
@ -60,14 +60,14 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertSame([ $this->assertSame([
'type' => 'card', 'type' => 'card',
'name' => 'pk_spam', 'name' => 'pk_spam',
'url' => 'https://aaronparecki.com/',
'photo' => 'https://scontent-frx5-1.cdninstagram.com/vp/74112f515c64726429c69fedcb927c2d/5CB64CF1/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=scontent-frx5-1.cdninstagram.com',
'note' => 'My website is https://aaronparecki.com.dev/ and http://aaronpk.micro.blog/about/ and https://tiny.xyz.dev/'
'nickname' => 'pk_spam',
'url' => 'https://www.instagram.com/pk_spam/',
'photo' => 'https://scontent-frx5-1.cdninstagram.com/vp/f17e1275a70fc32e93cbf434ddc32bcd/5B6CCC7A/t51.2885-19/11906329_960233084022564_1448528159_a.jpg',
], $data['data']['author']); ], $data['data']['author']);
$this->assertSame([ $this->assertSame([
'muffins', 'muffins',
'https://indiewebcat.com/'
'https://www.instagram.com/indiewebcat/'
], $data['data']['category']); ], $data['data']['category']);
$this->assertEquals('Meow #muffins', $data['data']['content']['text']); $this->assertEquals('Meow #muffins', $data['data']['content']['text']);
@ -105,9 +105,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/vp/a77f8672f977413d2eb5239cd6d5c4cf/5C3A4ADF/t51.2885-15/e15/15624670_548881701986735_8264383763249627136_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net'], $data['data']['photo']); $this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/vp/a77f8672f977413d2eb5239cd6d5c4cf/5C3A4ADF/t51.2885-15/e15/15624670_548881701986735_8264383763249627136_n.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net'], $data['data']['photo']);
$this->assertEquals(1, count($data['data']['video'])); $this->assertEquals(1, count($data['data']['video']));
$this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/vp/90ed8fe576cba16e258c0f4cfc05299a/5C3A129E/t50.2886-16/15921147_1074837002642259_2269307616507199488_n.mp4?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net'], $data['data']['video']); $this->assertEquals(['https://instagram.fsjc1-3.fna.fbcdn.net/vp/90ed8fe576cba16e258c0f4cfc05299a/5C3A129E/t50.2886-16/15921147_1074837002642259_2269307616507199488_n.mp4?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net'], $data['data']['video']);
$this->assertEquals('https://aaronparecki.com/', $data['data']['author']['url']);
$this->assertEquals('https://www.instagram.com/aaronpk/', $data['data']['author']['url']);
$this->assertEquals('Aaron Parecki', $data['data']['author']['name']); $this->assertEquals('Aaron Parecki', $data['data']['author']['name']);
$this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/45aee453740a714bf408f8947f89da8e/5CCB4B8E/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['author']['photo']);
$this->assertEquals('https://instagram.fsjc1-3.fna.fbcdn.net/vp/a2909937316893f18760f1077ca88fa1/5CBB520A/t51.2885-19/s150x150/14240576_268350536897085_1129715662_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', $data['data']['author']['photo']);
} }
public function testInstagramPhotoWithPersonTag() { public function testInstagramPhotoWithPersonTag() {
@ -123,9 +123,9 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertEquals('instagram', $data['source-format']); $this->assertEquals('instagram', $data['source-format']);
$this->assertEquals(2, count($data['data']['category'])); $this->assertEquals(2, count($data['data']['category']));
$this->assertEquals(['type'=>'card','name'=>'KmikeyM™️','url'=>'https://kmikeym.com/','photo'=>'https://instagram.fsjc1-3.fna.fbcdn.net/vp/ea5b988b616dbcc778b3013bf2426d70/5CCAC7FC/t51.2885-19/s320x320/20634957_814691788710973_2275383796935163904_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net','note'=>"The world’s first publicly traded person.\n\nAcct in collaboration with @norbertoinc\n\nBecome a shareholder today!\n"], $data['data']['refs']['https://kmikeym.com/']);
$this->assertContains('https://kmikeym.com/', $data['data']['category']);
$this->assertArrayHasKey('https://kmikeym.com/', $data['data']['refs']);
$this->assertEquals(['type'=>'card','name'=>'KmikeyM™️','nickname'=>'kmikeym','url'=>'https://www.instagram.com/kmikeym/','photo'=>'https://instagram.fsjc1-3.fna.fbcdn.net/vp/ea5b988b616dbcc778b3013bf2426d70/5CCAC7FC/t51.2885-19/s320x320/20634957_814691788710973_2275383796935163904_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net','note'=>"The world’s first publicly traded person.\n\nAcct in collaboration with @norbertoinc\n\nBecome a shareholder today!\n"], $data['data']['refs']['https://www.instagram.com/kmikeym/']);
$this->assertContains('https://www.instagram.com/kmikeym/', $data['data']['category']);
$this->assertArrayHasKey('https://www.instagram.com/kmikeym/', $data['data']['refs']);
} }
public function testInstagramPhotoWithVenue() { public function testInstagramPhotoWithVenue() {
@ -206,7 +206,8 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertSame([ $this->assertSame([
'type' => 'card', 'type' => 'card',
'name' => 'Aaron Parecki', 'name' => 'Aaron Parecki',
'url' => 'https://aaronparecki.com/',
'nickname' => 'aaronpk',
'url' => 'https://www.instagram.com/aaronpk/',
'photo' => 'https://instagram.fsjc1-3.fna.fbcdn.net/vp/45aee453740a714bf408f8947f89da8e/5CCB4B8E/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net', 'photo' => 'https://instagram.fsjc1-3.fna.fbcdn.net/vp/45aee453740a714bf408f8947f89da8e/5CCB4B8E/t51.2885-19/s320x320/14240576_268350536897085_1129715662_a.jpg?_nc_ht=instagram.fsjc1-3.fna.fbcdn.net',
'note' => '🔒 oauth.net 🎥 backpedal.tv 🎙 streampdx.com 📡 w7apk.com' 'note' => '🔒 oauth.net 🎥 backpedal.tv 🎙 streampdx.com 📡 w7apk.com'
], $data['data']); ], $data['data']);
@ -226,7 +227,8 @@ class InstagramTest extends PHPUnit_Framework_TestCase {
$this->assertSame([ $this->assertSame([
'type' => 'card', 'type' => 'card',
'name' => 'pk_spam', 'name' => 'pk_spam',
'url' => 'https://aaronparecki.com/',
'nickname' => 'pk_spam',
'url' => 'https://www.instagram.com/pk_spam/',
'photo' => 'https://scontent-frx5-1.cdninstagram.com/vp/74112f515c64726429c69fedcb927c2d/5CB64CF1/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=scontent-frx5-1.cdninstagram.com', 'photo' => 'https://scontent-frx5-1.cdninstagram.com/vp/74112f515c64726429c69fedcb927c2d/5CB64CF1/t51.2885-19/44884218_345707102882519_2446069589734326272_n.jpg?_nc_ht=scontent-frx5-1.cdninstagram.com',
'note' => 'My website is https://aaronparecki.com.dev/ and http://aaronpk.micro.blog/about/ and https://tiny.xyz.dev/' 'note' => 'My website is https://aaronparecki.com.dev/ and http://aaronpk.micro.blog/about/ and https://tiny.xyz.dev/'
], $data['data']); ], $data['data']);

Loading…
Cancel
Save