Community @ The Turning Gate

Support community for TTG plugins and products.

NOTICE

The Turning Gate's Community has moved to a new home, at https://discourse.theturninggate.net.

This forum is now closed, and exists here as a read-only archive.

  • New user registrations are disabled.
  • Users cannot create new topics.
  • Users cannot reply to existing topics.

You are not logged in.

#1 2016-05-13 19:26:35

angel
Member
From: Israel
Registered: 2013-06-18
Posts: 45
Website

Instagram Feed

I am trying to install an Instagram Feed on my website and after some research found the following code to use in php.

I inserted in the PHPlugins as below and have errors - any ideas please?

function ttg_canvas_bottom( $style, $path ) {
    echo '

$client_id = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$user_id = 'xxxxxxxxx';

$url = 'https://api.instagram.com/v1/users/'.$user_id.'/media/recent/?client_id='.$client_id;

$data = file_get_contents($url);
$json = json_decode($data);

$first_photo = $json->data[0];

// Change "standard_resolution" to "thumbnail" or "low_resolution"
$image = $first_photo->images->standard_resolution;
?>
<img src="<?php echo $image->;url; ?>;" alt="" /></pre>




Caption: <php echo $first_photo->caption->;text; ?>;

Created on <?php echo date("F j, Y, g:i a", $first_photo--->created_time); ?>;

User: <?php echo $first_photo->user->;full_name; ?>; (Username <?php echo $first_photo->user->;username; ?>;)

<img src="<?php echo $first_photo->;user->;profile_picture; ?>;" alt="" />
   
        ';
    return false;        // Replaces normal menu
} // END

Offline

#2 2016-05-13 20:59:32

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Instagram Feed

One problem is the single quotes inside the echo'

try either escaping them:

$client_id = \'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\';
$user_id = \'xxxxxxxxx\';

$url = \'https://api.instagram.com/v1/users/\'.$user_id.\'/media/recent/?client_id=\'.$client_id;

or changing them to double quotes:

$client_id = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$user_id = "xxxxxxxxx";

$url = "https://api.instagram.com/v1/users/".$user_id."/media/recent/?client_id=".$client_id;

Do this in a plain text editor like Notepad++ for Windows or TextWrangler for Mac.

After you've made these changes there may be other problems, but fix that first.

Note: don't escape or change the final single quote near the end of the function

 ';
    return false;        // Replaces normal menu
} // END

Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#3 2016-05-13 21:13:37

angel
Member
From: Israel
Registered: 2013-06-18
Posts: 45
Website

Re: Instagram Feed

Thank you, that removed all syntax errors.
Now I just see the code (as text) in the website.
I'm sure it is a simple fix and I am doing something wrong.

Any ideas please?

function ttg_canvas_bottom( $style, $path ) {
    echo '

$client_id = "xxx";
$user_id = "xxx";

$url = "https://api.instagram.com/v1/users/".$user_id."/media/recent/?client_id=".$client_id;

$data = file_get_contents($url);
$json = json_decode($data);

$first_photo = $json->data[0];

// Change "standard_resolution" to "thumbnail" or "low_resolution"
$image = $first_photo->images->standard_resolution;
?>
<img src="<?php echo $image->;url; ?>;" alt="" /></pre>




Caption: <php echo $first_photo->caption->;text; ?>;

Created on <?php echo date("F j, Y, g:i a", $first_photo--->created_time); ?>;

User: <?php echo $first_photo->user->;full_name; ?>; (Username <?php echo $first_photo->user->;username; ?>;)

<img src="<?php echo $first_photo->;user->;profile_picture; ?>;" alt="" />
   
        ';
    return false;        // Replaces normal menu
} // END

Offline

#4 2016-05-13 21:38:33

rod barbee
Moderator
From: Port Ludlow, WA USA
Registered: 2012-09-24
Posts: 17,830
Website

Re: Instagram Feed

Where did you get that code and do you have instructions as to where to place it?
ttg_canvas_bottom places stuff on the page itself.

And it looks like more of that code should be wrapped in php tags, like those variables at the beginning. They might belong in the <head> (ttg_head_end hook)
And there are html errors like a closing </pre> tag when there is no opening tag.


Rod 
Just a user with way too much time on his hands.
www.rodbarbee.com
ttg-tips.com, Backlight 2/3 test site

Offline

#5 2016-05-14 01:06:56

Matthew
Administrator
From: San Francisco, CA
Registered: 2012-09-24
Posts: 5,795
Website

Re: Instagram Feed

Hard to say what's going on, but that code, to me, looks like it's full of syntax errors.

$image->;url; is probably meant to be $image->url;

echo $first_photo->user->;full_name; is probably mean to be echo $first_photo->user; echo full_name; or echo $first_photo->user->full_name;

But really, this is some of the messiest PHP I've ever seen, so it's difficult to know what the intent is, and I'm certainly no PHP expert.


Matt

The Turning Gate, http://theturninggate.net

Offline

Board footer

Powered by FluxBB