1

Actually i've used this script to get the profile picture of instagram user

<script src="http://codeorigin.jquery.com/jquery-2.0.3.min.js"></script>
  <script type="text/javascript">
var user_id = <? echo $page_id; ?>;
var url = "https://api.instagram.com/v1/users/"+user_id+"?client_id=775829274b6f48c1ac2bf218dda60e16&callback=?";
$.getJSON(url, function(data) {
    $("body").append("<img src='"+data.data.profile_picture+"' />");

}
);

  </script>

The Output of this script is 100% what i need. All i need now is to take the image link to a PHP variable which is (+data.data.profile_picture+)

if tried to reload the same page with + ?link="+data.data.profile_picture+" so i can grab it with $_GET['link'] Like this:

window.location.href = location.href + '?link="+data.data.profile_picture+";

but it doesn't .. What should i do to pass this javascript variable to a PHP variable.

2 Answers 2

1

Try This

window.location.href = location.href + '?link='+data.data.profile_picture;
Sign up to request clarification or add additional context in comments.

1 Comment

This will cause an infinite loop if you don't use an if statement to check if $_GET['link'] is already set
0

You need to send your data to the PHP, and the simplest way would be using jQuery.ajax().

var picture = data.data.profile_picture;
$("body").append("<img src='"+picture+"' />");
$.ajax({
            url: "http://example.com/webservices/getProfilePicture.php",
            type: "POST",
            data: {
                'profile_picture': picture
            },
            success: function () {
                console.log('Success!');
                // Place eventual post-treatment here
            },
            error: function () {
                 console.log('Error..');
                 // Place eventual error-handling / debugging here
            }
        }
);

});

Then in PHP you can access it with this:

<?php $profile_picture = $_REQUEST['profile_picture']; ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.