Instagram get profile data - javascript

Is it possible to use jQuery or javascript to get the amount of followers a user has on instagram and then display that number inside a div element? I've found several PHP answers but I can't use PHP. Any help would be GREATLY appreciated.

Instagram supports RESTfull webservices. The solution you found for PHP can also be used in jquery. You just need to make jsonp calls to the server.
Hope this helps.

Trying to access Instagram API using jQuery
Use something similar. Use the resulting JSON data to print the followers number into a div.
$(document).ready(function(e) {
$('#fetch_followers').click(function(e) {
var $url = 'https://api.instagram.com/v1/users/{user-id}/?access_token={access-token}&count=100';
var $access_token = '{access-token}';
$.ajax({
method: "GET",
url: $url,
dataType: "jsonp",
jsonp : "callback",
success: function(data) {
$('#followers').append(data.counts.followed_by);
}
});
});
});
The code is rough, untested, but something along those lines will work.

Related

how to consume data from rest api using ajax jquery

i am new in j query ajax.i don't have idea how to fetch data from rest API using j query ajax. here i have created JS function to check whether passing URL working proper or not.
kindly help me.
<script type="text/JavaScript">
$.ajax({
type: "GET",
dataType: "jsonp",
url: "https://www.propertyfinder.ae/en/find-broker/ajax/search?page=1",
success: function(data){
alert(data);
}
});
</script>
You cannot do a cross domain call using ajax. what you can do is to do a php call like :
$website = file_get_contents('http://google.com');
and store it in a text file and access that using your ajax on your server using the same ajax file you have.
i had similar case that i had a php call on scheduler to grab text from url every minute and update a json file. then simply use :
$.getJSON( "ajax/test.json", function( data ) {
//your function
});
or use ajax! whichever you fancy

Jquery POST unicode string to codeigniter php

I'm trying to implement a custom suggestion engine using jquery.
I take the user input, call my codeigniter v2 php code in order to get matches from a pre-built synonyms table.
My javascript looks like this:
var user_str = $("#some-id").val();
$.ajax({
type: "POST",
url: "http://localhost/my-app/app/suggestions/",
data: {"doc": user_str},
processData: false
})
.done(function (data)
{
// Show suggestions...
});
My PHP code (controller) looks like this:
function suggestions()
{
$user_input = trim($_POST['doc']);
die("[$user_input]");
}
But the data is NOT posted to my PHP :( All I get as echo is an empty [] (with no 500 error or anything)
I've spent 2 days looking for an answer, what I've read in SO / on google didn't help. I was able to make this work using GET, but then again, this wouldn't work with unicode strings, so I figured I should use POST instead (only this won't work either :()
Anyone can tell me how to fix this? Also, this has to work with unicode strings, it's an important requirement in this project.
I'm using PHP 5.3.8
Try using the $.post method, then debug. Do it like this:
JS
var user_str = $("#some-id").val();
var url = "http://localhost/my-app/app/suggestions";
var postdata = {doc:user_str};
$.post(url, postdata, function(result){
console.log(result);
});
PHP
function suggestions(){
$user_input = $this->input->post('doc');
return "MESSAGE FROM CONTROLLER. USER INPUT: ".$user_input;
}
This should output the message to your console. Let me know if it works.
For those interested, this works for me, even with csrf_protection being set to true
var cct = $.cookie('csrf_the_cookie_whatever_name');
$.ajax({
url: the_url,
type: 'POST',
async: false,
dataType: 'json',
data: {'doc': user_str, 'csrf_test_your_name': cct}
})
.done(function(result) {
console.log(result);
});

How can I pull content from blogger onto my webpage?

I want to dynamically pull the posts from blogger to my HTML/CSS/PHP webpage. What would be the best way to go about doing that?
For that, should I use JavaScript, PHP, AJAX or something else?
You could use jQuery .ajax() request using Blogger API.
https://developers.google.com/blogger/docs/3.0/using#RetrievingABlog
For example: (something like this, not tested)
$.ajax({
type: "GET",
dataType: "jsonp",
url: "https://www.googleapis.com/blogger/v3/blogs/2399953?key=YOUR-API-KEY",
success: function(data) {
console.log(data);
}
});
For posts it looks like you will need to use this URL and whatever your API key is.
https://www.googleapis.com/blogger/v3/blogs/2399953/posts?key=YOUR-API-KEY

Setting up a sticky post tag in tumblr?

Does anyone have any clues about how one might go about setting up a sticky post function using a special tag in tumblr? I know that the Single A theme has this functionality but there's no documentation and I'm trying to avoid decoding it all. Has anyone done this?
You would choose to use a specific tag for the post, say, 'sticky' and then run an API call only on posts tagged with Sticky, limiting to 1 (optional).
http://api.tumblr.com/v2/blog/[YOURBLOG].tumblr.com/posts/?api_key=[YOURAPIKEY]&limit=1&tag=sticky
More info on the API can be found here: http://www.tumblr.com/docs/en/api/v2#posts
The API call would look something like this in JS:
$.ajax({
url: '[URL_FROM_ABOVE]&jsonp=?',
dataType: 'jsonp',
type: 'get',
success: function(data){
// do something with your data
}
});

Change state of HTML page without refresh?

Currently, I have a mySQL database setup as follows:
fullname
address
cellphone
homephone
email
It is for users registering for my company. In the employee section of the site, there is a drop down menu, which is populated from the fullname row of the database. Is there a way using JavaScript/AJAX to display the entire column of data, based on the person currently selected in the drop down menu?
As pimvdb and myself stated, you will require a server-side language to accomplish this.
Yes there is a way.
Look into jQuery
http://jquery.com/ where you can create element.
Use ASP.NET to read the data from the SQL server, then make a jQuery AJAX call to your ASP.NET page, and finally display it.
Here is a snippet from my code, that should help you out.
$.ajax({
type: "POST",
url: "YOURPAGE.aspx/YOURMETHOD",
contentType: "application/json; charset=utf-8",
data: "{ 'upc':'" + value + "' }",
dataType: "json",
success: function (result) {
var yourelement = document.getElementById("someelement").options;
//mess around with the element here
}
},
error: function(){}
});
It's easy with AJAX. Just have a page that prints the resultset formatted however you like. Then do a simple jQuery call like:
$("#personDiv").load("person.php?name="+$("#fullname").val());
i highly recommend the use of jQuery and the use of .ajax()

Categories

Resources