how to put google+ photos with Json & google API - javascript

i have a problem with the Google API.
I want to put pictures of a public album (google+) in some background-image in js.
i am not really familiar with Json
var data = $.getJSON('https://plus.google.com/photos/ACCOUNT_ID/albums/ALBUM_ID');
function displayGallery(data){
var l = data.feed.entry.length;
for (var i = 0; i < l; i++) {
var item = data.feed.entry[i];
$('#m'+ i ).css("backround-image",data);
}
i saw a similar post : Using jQuery $.getJSON() with Google Picasa Data API
But it was hard to understand it (and excuse my english).
Thanks in advance for any help !

I didn't have time to continue this project, but i think i finally took the right direction. I pretty close to the result i want.
$(document).ready(function() {
console.log("hello world");
$.get('https://picasaweb.google.com/data/feed/api/user/userID/albumid/albuID', function(data){
var entries = data.getElementsByTagName('entry');
console.log(entries);
// var entry = entries[0];
for(var i =0; i< entries.length; i++){
console.log(entries[i]);
console.log($(entries[i].getElementsByTagName('content')[0]).attr("src"));
}
});
});
The only real problem is that there is a security on web browser that doesnt permit you to well acces to this infos . You need to desable web security

Related

How to get the JavaScript display results "on click" query to display ALL results

I'm trying to create an excel spreadsheet compiling all responses from an online survey on Google Chrome, there are over 500 entries and to click on each entry to get the results would take forever.
I've pinpointed the problem on the Google Chrome > Inspect > Elements at the point with the multiple display results onclick. Is there any way to remove the onclick to be able to download or copy-paste all the results at once?
I've attached a picture below:
https://imgur.com/wyxoRjN
I would appreciate any advice on how best to do this! Apologies in advance as I have absolutely no programming experience so I might not get all the terminology.
EDIT
You should check with the online survey service since there should be a way to export your results to csv (csv can be opened in excel). (Author indicated there was no way)
Before using website scraping code, make sure that the service is alright with you grabbing the data that way. The code should not be scraped for malicious intent or means that break terms of the agreement.
IF the structure that you provided is consistent then you should be able to copy the code below (or from the javascript pane in the fiddle), run it in the console on the page with the data (F12, console tab in chrome), the data should print to the console where you can copy it, and then use an online tool(like this) to convert it from json to csv for excel.
var getData = () => {
var table = document.getElementById('table_survey'); // get table
var data = []; // holds all the data
for (i = 0; i < table.rows.length; i++) { //loops through rows
var pieceOfData = {}
var cells = table.rows.item(i).cells; //gets cells
for (var j = 0; j < cells.length; j++) { //loops through each cell
var cellVal = cells.item(j).innerHTML; // get piece of data
// store data in object dependent on index
//assumes only 4 <td>s with valid data
switch (j) {
case 0:
pieceOfData.id = cellVal
case 1:
pieceOfData.data1 = cellVal
case 2:
pieceOfData.data2 = cellVal
case 3:
pieceOfData.day = cellVal
}
}
data.push(pieceOfData); // add data object to array
}
return data; // return all the data
}
var allData = getData(); // puts all the data in a variable
console.log(allData); // print data to console
My Fiddle: https://jsfiddle.net/m852hge8/
In my view the easiest, low-tech way to do this is to paste the whole thing in a text editor such as Notepad++ (which is free), and do a lot of "replace all" to remove what you don't want (by replacing by blank).
For example replace "tr onclick="displayResults(" by "" (i.e. blank)
The simplest solution is to switch off the Javascript of your browser while you work on the CSV and swith it back on when you are finished. The onclick is executing Javascript and if it is switched off for your browser, then it will not be executed.
This should work, however, if Javascript is needed to display the data you need to extract, then you need Javascript to be switched on, but you can override displayResult to be a dummy function, so you will not experience the problematic behavior when you click in your browser console:
displayResult = function() {};
This should work, but if, for some reason displayResult is redefined, then you can remove the onclick of each element. If there are too many elements for manual execution, then you can execute something like this in your console:
var survey = document.querySelectorAll("#table-survey tr");
for (var index = 0; index < survey.length; index++) {
survey[index].onclick = "";
}

javascript illustrator copy pdf documents and stack them issue

I'm looking for a way to copy pdf documents and stack them resized (I think resize works as duplicate, so once this works I will be able to complete my script).
I've been using .duplicate for now, and I can only manage to copy 1 item[0] on the same doc. Besides if I copy element by element I won't be able to replace them easily that's why I want to copy the whole document
I'm opening every script I find to understand a possible method.
Syntax is ok
var targetFile = app.documents.add(); //this is my output file - it is created
folder = Folder.myDocuments; //this paragraph works for now
sourceFolder = folder.selectDlg("source");
for ( i = 0; i < files.length; i++ ){
var sourceDoc = app.open(files[i]);
var doc = app.activeDocument;
for (l = 0; l < doc.pageItems.length; l++) { //corrected error
doc.pageItems[i].selected = true;
}
var mySel = app.activeDocument.selection; //this paragraph need rework
newItem = mySel[0].duplicate(targetFile); //mysel.duplicate(targetFile) is not a function
// MAIN ERROR
}
I use ESTK and notepad++ and have checked the variable, nothing obviously wrong during F10 debug. Using Jongware's CHM reference guide and some github tutorial but they tend to help for single operation script. My goal is to have script without GUI to reduce errors and time to proceed
Thank you for your time
EDIT: spotted an error with i used two times in a loop
Simple self solution:
var mySel = app.activeDocument.selection;
app.executeMenuCommand('copy');
targetFile.activate();
newItem = app.executeMenuCommand('paste');

Get latest tweets of specific user

I need to get the latest tweets of specific user using javascript. I've found some script for that. Here is it:
<script>
$(document).ready(function(){
loadLatestTweet();
});
function loadLatestTweet(){
var numTweets = 1;
var _url = 'https://api.twitter.com/1/statuses/user_timeline/CypressNorth.json?callback=?&count='+numTweets+'&include_rts=1';
$.getJSON(_url,function(data){
for(var i = 0; i< data.length; i++){
var tweet = data[i].text;
var created = parseDate(data[i].created_at);
var createdDate = created.getDate()+'-'+(created.getMonth()+1)+'-'+created.getFullYear()+' at '+created.getHours()+':'+created.getMinutes();
tweet = tweet.parseURL().parseUsername().parseHashtag();
tweet += '<div class="tweeter-info"><div class="uppercase bold">#CypressNorth</div><div class="right">'+createdDate+'</div></div>'
$("body").append('<p>'+tweet+'</p>');
}
});
}
</script>
but i get an error, that says Status Code:401 Unauthorized. I've changed the version code to 1.1, but the same error. So, I want to know, how can I pass the application id or application key to this url. And more, is there any javascript lib which works with the newest twitter api. Thanks a lot
The quick answer to this is version 1.0 is no longer active and version 1.1 requires OAuth for almost every api endpoint url.

geoxml3 and placemarks not functioning

Well I've read through and tried to find out the solutions but fail...
I followed the instructions from the geoxmlv3: http://code.google.com/p/geoxml3/wiki/Usage
here is a quote from that document:
<script type="text/javascript">
var myParser = new geoXML3.parser({afterParse: useTheData});
myParser.parse('my_geodata.kml');
function useTheData(doc) {
// Geodata handling goes here, using JSON properties of the doc object
for (var i = 0; i < doc.placemarks.length; i++) {
doSomething;
}
};
</script>
According to the documentation, the doc.placemarks should be working and return an array of json of placemarks in the KML file, unfortunately this 'doc' doesn't even exist(undefined), any idea?
If you are using the poly branch, "doc" is an array.
function useTheData(doc) {
// Geodata handling goes here, using JSON properties of the doc object
for (var i = 0; i < doc[0].placemarks.length; i++) {
doSomething;
}
};
I will fix the example in the documentation.
working example
Why don't you use KmlLayer of Google Maps API v3?
It's easy to map information from KML file onto the map.
https://developers.google.com/maps/documentation/javascript/layers#KMLLayers

getting pictures into an array in javascript

im kinda new to javascript i mean i know the syntax but not so much the libraries.
i need some help to get some files (pictures) from a folder into an arry lets say:
var[] pictures = ?;
(the folder is in my project and contain some pictures)
so i can loop over them and diplay them on the page i did some search but i didnt find any guide on how to do this.
i realy want to understand on how to do this for future projects even a link to known guid you guys know we will be a big help.
if it help im using asp.net.
Well, there are a lot of ways to approach the problem, to me what you can do is (if you don't know the location of the images beforehand) make a service that returns the src of every image, store that in an array, and then show them in the page.
I believe you are using jQuery so you can make an ajax request like this:
jQuery.ajax({
url: /*path to*/"Service.asmx/getSources"
//options, check documentation
});
then, from asp, make a new service (Service.asmx in my case) and create a method that returns the location of the pictures (in my case the method is called getSources)
I recommend you use JSON (and jQuery.getJSON() method) so you can return a List<string>.
Lastly you can iterate or store the sources in an array, I'll put an example with the getJSON method
var sources = []
jQuery.getJSON("Service.asmx/getSources", function(data) {
for(var i = 0, len = data.length; i<len ; i++) {
sources.push(data[i]);//store every source in the array
}
});
once you have the sources you can display them like this fiddle
Tell me if it helped or if you need another solution.
If you want an array of pictures just to display them later, you can simply use:
var sources = [
"path/to/yourImage1.jpg",
"path/to/yourImage2.jpg",
// ...
"path/to/yourImageN.jpg",
];
var pics = [];
for(var i = 0; i < sources.length; i++) {
var pic = new Image();
pic.src = sources[i];
pics[i] = pic;
}

Categories

Resources