Retrieval/Changing of Profile Picture Google Profile API - google-profiles-api

I am able to retrieve profile information via an AJAX call in Jquery using this code:
var url = 'https://www.google.com/m8/feeds/profiles/domain/{DOMAIN_NAME}/full';
$.ajax({
url: url
+'?access_token='
+accessToken,
headers: {
'GData-Version': '3.0',
'If-Match': '*'
},
async: false,
dataType: 'text',
success: function(data) {
$('#result').text(data);
}
});
};
However when I try to retrieve a picture with the same access token:
var url = 'https://www.google.com/m8/feeds/profiles/domain/{MY_DOMAIN}/full/{USER_NAME}';
$.ajax({
url: url
+'?access_token='
+accessToken,
headers: {
'GData-Version': '3.0'
},
async: false,
dataType: 'text',
success: function(data) {
$('#result').text(data);
}
});
I get the error:
401 (Token invalid - AuthSub token has wrong scope)
The scope I'm using is the one provided on the profile data api page:
https://www.google.com/m8/feeds/profiles
How do I get the correct authorization? Does the access token provided not do the job?

For profile pictures, I believe the URL of the form should be
https://www.google.com/m8/feeds/photos/profile/domainName/userName
Here is the documentation:
https://developers.google.com/google-apps/profiles/#retrieving_photo
Would you try that and see if it works?

Try using this path as scope
https://www.google.com/m8/feeds/
You can refer this post

Related

How to Post JSON Data to server in phonegap

hi i write in this code but i get Error like UNdefined how we can resolve this issue if any one know this answer plz let me know
$.ajax({ type: "POST", contentType:"application/json; charset=utf-8", dataType: "application/json", url:"some url",
data :{familyVoterId:'0',boothId:'0',voterId:'59136604',previousEnrollmentNumber:'29422415',casteId:'62',street:'hamlet',voterRelationId:'8',cadrePrevYear:'',relativeName:'DESSAPPA',previousRollesList:[{fromDateStr:'2012-10-24',cadreRoleId:'1',cadreCommitteeId:'1',cadreCommitteeLevelId:'1',toDateStr:"2013-10-24"}],partyMemberSinceStr:"2001-10-24",uniqueKey:"10d11073-a8b1-4764-bf2f-e2c0a269e9cd",nameType:"Voter",panchayatId:"0",age:28,surveyTimeStr:"2014-10-24 15:05:15",gender:"M",relationTypeId:8,bloodGroupId:3,dobStr:"1968-02-02",nomineeGender:"1",photoType:"VOTER",voterCardNumber:"UXN0862806",longititude:"78.413",aadheerNo:"987654321",candidateAadherNo:"12345678910",educationId:"2",nomineeAge:"21",previousParicaptedElectionsList:[{"electionTypeId":17,candidateId:"30126",constituencyId:"461"}],voterName:"RAMAKRISHNA",occupationId:"1",houseNo:"3-60",cadreFamilyDetails:[],createdUserId:"152",refNo:"TR-T-9999-12985",constituencyId:"282",latitude:"17.4278",nomineeName:"nominee",mobileNumber:"9999999999"},
success: function(data)
{
alert("success");
},
error: function(msg)
{
alert(msg.message);
}
});
Also, in addition, the reason it is failing in the first place is because you need to do a cross-domain post. In order to do this correctly through jQuery, you need to use the following options:
dataType: 'jsonp',
cache: false,
I reproduced your error. In Chrome if you click inspect element and then select the Console tab you can see the error message :
XMLHttpRequest cannot load file:///D:/DeleteME/pyMail/some%20url.
Cross origin requests are only supported for protocol schemes: http,
data, chrome-extension, https, chrome-extension-resource.
As mentioned before you need to specify the data type as jsonp if your are posting to another domain.
Example:
$.ajax({ type: "POST", contentType:"application/jsonp; charset=utf-8", dataType: "application/json", url:"http://www.google.com",
data :{familyVoterId:'0',boothId:'0',voterId:'59136604',previousEnrollmentNumber:'29422415',casteId:'62',street:'hamlet',voterRelationId:'8',cadrePrevYear:'',relativeName:'DESSAPPA',previousRollesList:[{fromDateStr:'2012-10-24',cadreRoleId:'1',cadreCommitteeId:'1',cadreCommitteeLevelId:'1',toDateStr:"2013-10-24"}],partyMemberSinceStr:"2001-10-24",uniqueKey:"10d11073-a8b1-4764-bf2f-e2c0a269e9cd",nameType:"Voter",panchayatId:"0",age:28,surveyTimeStr:"2014-10-24 15:05:15",gender:"M",relationTypeId:8,bloodGroupId:3,dobStr:"1968-02-02",nomineeGender:"1",photoType:"VOTER",voterCardNumber:"UXN0862806",longititude:"78.413",aadheerNo:"987654321",candidateAadherNo:"12345678910",educationId:"2",nomineeAge:"21",previousParicaptedElectionsList:[{"electionTypeId":17,candidateId:"30126",constituencyId:"461"}],voterName:"RAMAKRISHNA",occupationId:"1",houseNo:"3-60",cadreFamilyDetails:[],createdUserId:"152",refNo:"TR-T-9999-12985",constituencyId:"282",latitude:"17.4278",nomineeName:"nominee",mobileNumber:"9999999999"},
dataType: 'jsonp',
success: function(data)
{
alert("success");
},
error: function(msg)
{
alert(msg.message);
}
});
Message is not a property of the XHR object msg in your error callback function. That is why it shows undefined in your alert box. You can try to alert msg.statusText and see the status text.
Please check the documentation http://api.jquery.com/jquery.ajax/
(The jqXHR Object section)

Using HTTP GET with JQuery

I'm trying to use a GET HTTP cal, I got the request to work with the Advanced REST client (Chrome plugin) but cannot get it to work in JQuery.
Following the advice from this thread, I've set up the following:
$(document).ready(function() {
$('.ap1').click(function(){
$.ajax({
url: 'https://api2.panopta.com/v2/monitoring_node/41',
type: 'GET',
dataType: 'json',
success: function() { alert('hello!'); },
error: function() { alert('boo!'); },
beforeSend: setHeader
});
});
function setHeader(xhr) {
//extra stuff from REST CLIENT
xhr.setRequestHeader('Authorization', 'ApiKey nGhhAjGshbOu4dhLYvGY');
} });
This is the output I'm trying to get (successfully with REST client)
{
url: "https://api2.panopta.com/v2/monitoring_node/41"
hostname: "phoenix01.monitorengine.com"
ip_address: "65.23.158.149"
name: "Phoenix"
textkey: "na.west.phoenix01"
}
I just want to be able to access the name variable from that JSON and pass it through my function. I wanted to at least get the above code to work before I try to figure out how to create an object so I can successfully call the name, something like .append(object.name)
I just started learning JQuery and this is my first post so sorry if I didn't include enough details.
You can't apply ajax calls to other domains. You can make workaround using server-to-server calls via curl() or file_get_content(url), and then make a js call to your script.
First make php file, which will call the server note that if you want to use file_get_contents you should allow_url_fopen in your php.ini:
myProxy.php
<?
$content = file_get_contents($yourUrl);
// do whatever you want with the content then
// echo the content or echo params via json
?>
your js should make call to your PHP, so you have workaround Same Domain Policy:
$.ajax({
url: 'myProxy.php',
type: 'GET',
dataType: 'json',
success: function() { alert('hello!'); },
error: function() { alert('boo!'); },
beforeSend: setHeader
});
});
I am not sure if your api info is correct, but I think the main thing you need to do is change to jsonp instead of json due to the same origin policy that musa mentions.
The following JS fiddle "works" but the request is not authorized at the server: http://jsfiddle.net/cf8S9/.
$(document).ready(function() {
$('#button').click(function(){
$.ajax({
url: 'https://api2.panopta.com/v2/monitoring_node/41',
type: 'GET',
dataType: 'jsonp',
success: function() { alert('hello!'); },
error: function() { console.log(arguments);alert('boo!'); },
beforeSend: setHeader
});
});
function setHeader(xhr) {
//extra stuff from REST CLIENT
xhr.setRequestHeader('Authorization', 'ApiKey nGhhAjGshbOu4dhLYvGY');
} });

Cross domain ajax call is not working in IE

I am doing a cross domain ajax call.
This is inserting data in the mysql database.
var urlsearch = "http://192.168.10.113:8080/collective-intellegence/StoreClicks?userid=" + userId + "&query=" + query;
$.ajax({
type: 'POST',
url: urlsearch,
dataType: 'json',
success: function (data) {
}
});
When I run the above code it is showing an error message this
XMLHttpRequest cannot load http: //192.168.10.113:8080/collective-intellegence/StoreClicks?userid=1&query=python&url=http://www.ourgoalplan.com/KLMS/TipView.aspx?id=1785. Origin http: //192.168.9.185 is not allowed by Access-Control-Allow-Origin.
but data is successfully inserting the database in all browser except IE.
Please help to solve the problem
Thanks in advance.
As #davidrac suggested, you can use JSONP as below:
jQuery.ajax({
type: 'POST',
url: urlsearch,
dataType: 'jsonp',
jsonp: 'json.wrf'
success: function (data) { }
});
You have to add the json.wrf parameter to your query string with name of your callback function, to get properly padded response from Solr.
You should probably use JSONP or some other workaround.
See here and here for explanation of the problem.
When you are outputting the response from the server, add this header:
Access-Control-Allow-Origin: *
This will make the XHRs in IE to allow. For more information, please check HTTP access control (CORS).
In case of PHP, you can do it this way:
<?php
header("Access-Control-Allow-Origin: *");
?>
This code should work as long as IE is 8+ and the server response include the Access-Control-Allow-Origin: [Allowed origins] HTTP header.
If (XDomainRequet) {
//just an example
var xdr = new XDomainRequest();
xdr.open("post", url);
xdr.send();
}
else
{
$.ajax({
type: 'POST',
url: urlsearch,
dataType: 'json',
success: function (data) {
}
});
}

Crossdomain request

I try to load static html pages from another server.I make crossdomain request.
$(document).ready(function (){
$("div[src]").each(function(){
var staticFileURL = $(this).attr('src');
$.ajax({
url: staticFileURL,
dataType: 'jsonp',
data: {},
error: function(xhr, status, error) {
alert(error);
},
success: function() {
alert("success");
},
jsonp: false,
jsonpCallback: 'jsonpCallback'
});
});
});
But I got in chrome error "SyntaxError:Unexpected token <".
In FF "SyntaxError:Invalid xml attribute value".
What's wrong.Could somebody help me?
JSONP is to get json data from the server, it looks like you are trying to received HTML data.
Try to put your HTML data inside JSON object on the server and then read that HTML on the success callback:
for example, your json data from the server:
{ html: "<html><head>...</head></html>" }
also, your success callback should look like:
success: function(**data**){
}

ExtJS Twitter timeline

I am trying to build a simple twitter timeline feature into one of my apps, but falling short of knowledge and cannot really find any decent tutorials online.
Is there a different way in using JSON and JSONP request in ExtJS?
Code:
Ext.Ajax.request({
url: 'https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=NynasBo&count=2',
method: 'GET',
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
console.dir(obj);
},
failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status);
}
});​
Response:
XMLHttpRequest cannot load https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=NynasBo&count=2&_dc=1331218369365 Origin is not allowed by Access-Control-Allow-Origin.
Suspecting it should only be a JSONP request...
any help is appreciated.
Yes, you have to use JSONP for the same. So, either it will be request like this:
Ext.data.JsonP.request({
url: 'YOUR JSONP URL',
callbackName: 'someCallbackFunctionName',
success: function(data) {
console.log(data);
}
});
Else you have to use ScriptTagProxy like this:
var store = Ext.create('Ext.data.Store', {
model: 'User',
proxy: {
type: 'jsonp',
url : 'https://api.twitter.com/1/statuses/user_timeline.json?include_entities=true&include_rts=true&screen_name=NynasBo&count=2'
}
});