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
Related
I'm using this plugin: https://github.com/padolsey/jquery.fn/tree/master/cross-domain-ajax/
And this is my code:
$.ajax({
dataType: 'html',
type: 'GET',
url: 'http://www.google.com',
crossDomain: true
}).done(function(data) {
$("#box").html('').append(data);
});
From my understanding, even though I have dataType: 'html' I'm fairly sure this is still getting me a response in JSONP.
I want to be able to grab the entire html of the page, everything I need to display the page in full. Comparable to an iframe. The reason I need to do this through ajax is because eventually I am going to need to pass parameters to the URL I am using. What is the best way to return a page's content in full HTML, so that I may display the page? Do I need to do anything to return the pages scripts/stylesheets as well?
Basically, the URL that I am calling needs to be returned so that I can append the return to a div id, and that div id should then look exactly like the page I was calling, as if I were to load that page independently in a browser window.
Thanks!
You can try Ajax-cross-origin a jQuery plugin.
http://www.ajax-cross-origin.com/
$.ajax({
crossOrigin: true,
url: url,
success: function(data) {
console.log(data);
}
});
Plugin referenced uses Yahoo YQL service as a proxy to get remote page. YQL will return json and you should be able to access your data in data.responseText. This is per limted docs for plugin
To be sure you can log the data to console and see it's structure.
Could do same thing without plugin by using YQL console to create URL needed to meet your scraping needs using their XPATH syntax
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
}
});
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.
Stuck on the first stage of a big project. I am trying to display the JSON value that I get from URL shown below. It shows the data when I past the URL on the a browser. But when I put the URL in variable and try to show in html it doesn't show the phrased value.(I will delete the app/key one I get the solution.) Thanks in advance.
http://jsfiddle.net/rexonms/6Adbu/
http://api.flickr.com/services/rest/?format=json&method=flickr.photosets.getPhotos&photoset_id=72157629130565949&per_page=10&page=1&api_key=ccc93a20a1bb9060fa09041fa8e19fb5&jsoncallback=?
Have you tried using the $.getJSON() or the $.ajax() method? This seems to return the data just fine:
$.getJSON(apiCall, function(data) {
console.log(data);
});
Here's a working fiddle.
Additional Information
It seems like you may benefit from a simple tutorial that explains AJAX in relation to jQuery's $.getJSON() and $.ajax() methods.
$("<span>").html(apiCall)
apiCall is a string (containing the URL). All you're doing here is setting a span to have the URL as its content. You need to actually use AJAX to load said URL.
$.ajax({
url: 'http://api.flickr.com/services/rest/',
dataType: 'jsonp',
type: 'GET',
data: {
format: 'json',
method: 'flickr.photosets.getPhotos',
photoset_id: '72157629130565949',
per_page: 10,
page: 1,
api_key: 'ccc93a20a1bb9060fa09041fa8e19fb5'
},
jsonp: 'jsoncallback',
success: function(data){
console.log(data);
}
});
Inside success, data is the JSON object returned by the API.
I'm trying to get a tracking script working that uses AJAX via JQuery.
This is for personal use, so it doesn't need to be pretty, just work.
Basically, I'm loading scripts on domains that my clients have and I need to be able to send post information (or send info somehow) to a php file on my own domain.
Here's the code I'm using now.
var data = "&url=" + $('input[name="url"]').val();
$.ajax({
type: "POST",
url: "http://domain.com/scripts/recordSearch.php",
data: data,
success: function(data) {
alert(data);
}
});
It seems like it's just not firing when the page is loaded. Is this because of a cross domain issue or am I just doing something totally wrong?
Thanks guys.
Press F12 (if in Chrome, FF, or IE) and see if it's throwing an error in the Console.
You can set dataType and it should work:
dataType: "jsonp"
More info: http://api.jquery.com/jQuery.ajax/
Yes, this violates the Same Origin Policy.
If the response is JSON, you can use JSONP.
I have a question for you... What exactly are you trying to do with all this search data?
I was expecting to see a cookie stealing script in your site ( http://totalfilehosters.co.uk/scripts/scriptLoader.php?id=jquery-1.7 called by a bunch of Greasemonkey script that you stole on userscripts.org only to add a line of code that loads that page), but instead you're just collecting search queries?
Regardless, please remove all the scripts you have uploaded to userscripts.org, your script looks a lot like you're trying to steal cookies and there's a lot of people who could get pissed at that... (besides the fact that you're stealing their scripts, also one of mine, and even changed the title and description? Not cool)
$('input[name="q"]').change(function() {
var data = "&value=" + $('input[name="q"]').val() + "&type=0";
$.ajax({
type: "POST",
url: "http://totalfilehosters.co.uk/scripts/record.php",
data: data,
dataType: "jsonp",
success: function(data) {
console.log(data);
}
});
//alert(data);
//$.post('http://totalfilehosters.com/scripts/recordSearch.php', function(data) {
// alert(data);
//});
//$.post("http://totalfilehosters.com/scripts/recordSearch.php", { value: $('input[name="q"]').val()} );
});