I'm trying to run the sample from Google's API sample here in Script.google.com.
Sample Code:
function getClicks(shortUrl) {
var url = UrlShortener.Url.get(shortUrl, {
projection: 'ANALYTICS_CLICKS'
});
Logger.log('The URL received %s clicks this week.', url.analytics.week.shortUrlClicks);
}
Error:
Required parameter: shortUrl (line 2, file "Code")
What am I missing?
Related
Im trying to Login with Twitter with Firebase in my app i set up everyting but i get this error in console:
Error Domain=TWTRNetworkingErrorDomain Code=-1011 "Request failed:
forbidden (403)" UserInfo={NSLocalizedFailureReason=Twitter API error
: Callback URL not approved for this client application.
Approved callback URLs can be adjusted in your application
settings (code (null)), TWTRNetworkingStatusCode=403,
NSErrorFailingURLKey=https://api.twitter.com/oauth/request_token,
NSLocalizedDescription=Request failed: forbidden (403)
I have set the Callback URL in my twitter settings but i get still that error
That´s my code:
let twitterLoginBtn = TWTRLogInButton { (session, error) in
if let error = error {
debugPrint("Couldn´t LogIn with Twitter: ", error)
return
}
if let session = session {
let credentials = TwitterAuthProvider.credential(withToken: session.authToken, secret: session.authTokenSecret)
self.firebaseLogin(credentials)
print("signed in as \(session.userName)")
} else {
print("error: \(error!.localizedDescription)")
return
}
}
twitterLoginBtn.center.x = twitterLoginView.center.x
twitterLoginView.addSubview(twitterLoginBtn)
heres twitter settings:
To use the SignIn with Twitter service, you have to add the Firebase (like my-app-12345.firebaseapp.com/__/auth/handler) callback URL you're using to a whitelist in your Twitter App Dashboard!
More information here in the Twitter API documentation ;)
Has anyone tried MessengerExtensions.requestPaymentCredentials using the facebook messenger extension sdk (refer documentation) ?
I am trying to call this in my client side javascript code and I am not getting any data. Below code doesn't alert me neither with email nor with error.
Here is my client side javascript code :
window.extAsyncInit = function() {
MessengerExtensions.requestPaymentCredentials(function success(name, email, cardType, cardLastFourDigits, shippingAddress) {
alert("Email" +email);
}, function error(err) {
alert("Messenger Extension error in getting payment credentials" + err);
});
};
Note : I am able to get user profile data using MessengerExtensions.getUserID by similar code.
The Servoy Framework does not support standard methods of calling a URL (eg: AJAX, JQuery, etc.). How does one go about posting a JSON object to a URL?
The Servoy JavaScript framework relies on the http plugin (included as aprt of Servoy) to make HTTP Posts.
Here is some sample code of how to post JSON to an API using Servoy. I have also included some basic error handling. Refer to the code comments for explanations of what the code is doing:
var sURL = 'http://www.example.com/myapipath/';
var oJSON = {"employees":[
{"firstName":"John", "lastName":"Doe"},
{"firstName":"Anna", "lastName":"Smith"},
{"firstName":"Peter", "lastName":"Jones"}
]};
var sClient = plugins.http.createNewHttpClient(); // HTTP plugin object
var sPoster = sClient.createPostRequest(sURL); // Post request object
sPoster.addHeader('content-type','application/json'); // required for JSON to be parsed as JSON
sPoster.setBodyContent(JSON.stringify(oJSON));
application.output('Executing HTTP POST request and waiting for response from '+sURL, LOGGINGLEVEL.INFO);
var sResponse = null;
var sResponseData = "";
var nHttpStatusCode = 0;
var sCaughtException = '';
try {
nHttpStatusCode = (sResponse = sPoster.executeRequest()).getStatusCode(); // POST JSON request to API
}
catch (e) {
// This handles the case when the domain called does not exist or the server is down, etc.
// in this case there will be no HTTP status code returned so we must handle this differently
// to prevent the Servoy application from crashing
sCaughtException = e['rhinoException'].getMessage();
if (-1 != sCaughtException.indexOf('TypeError: Cannot call method "getStatusCode"')) {
application.output('WARNING: Could not determine HTTP status code. The server might be down or its URL might be invalid.', LOGGINGLEVEL.WARNING);
}
else {
application.output('WARNING: caught unknown HTTP POST exception: '+sCaughtException, LOGGINGLEVEL.WARNING);
}
}
// SUCCESS!:
if (200 == nHttpStatusCode) { // HTTP Ready Status
sResponseData = sResponse.getResponseBody(); // Get the server's response text
application.output('Successful, response received from server:',LOGGINGLEVEL.INFO);
application.output(sResponseData, LOGGINGLEVEL.INFO);
// put your code to handle a successful response from the server here
}
else {
// insert your code to handle various standard HTTP error codes (404 page not found, 403 Forbidden, etc.)
}
I'm trying to query for page data and posts data using graph api. Suddenly, I'm getting OauthException error code 2. I'm using fbGraph module for nodejs. Does anyone know what is wrong? Here is my code:
var fbGraph = require('fbgraph');
var params = {
access_token: userToken,
limit: 500,
since: moment(startDate).format(constants.DATE_FORMAT),
until: moment(startDate).clone().add('months', 1).format(constants.DATE_FORMAT),
fields: 'id,message,description,call_to_action,shares,likes,comments.limit(1000000).fields(id),application.fields(name)'
};
var url = '/' + facebookPageId + '/posts';
fbGraph.get(url, params, callback);
I am using following code to retrieve facebook accessToken
string url = "https://graph.facebook.com/oauth/access_token?" +
"client_id={0}" +
"&redirect_uri={1}" +
"&client_secret={2}" +
"&code={3}";
url = string.Format(url, clientId, redirectUri.EncodeUrl(), clientSecret, code);
//Create a webrequest to perform the request against the Uri
WebRequest request = WebRequest.Create(url);
try
{
//read out the response as a utf-8 encoding and parse out the access_token
using (WebResponse response = request.GetResponse())
{
using (Stream stream = response.GetResponseStream())
{
//string urlRedirects = response.ResponseUri.ToString();
Encoding encode = Encoding.GetEncoding("utf-8");
if (stream != null)
{
StreamReader streamReader = new StreamReader(stream, encode);
string accessToken = streamReader.ReadToEnd().Replace("access_token=", "");
streamReader.Close();
response.Close();
return accessToken;
}
}
}
}
catch
{
return null;
}
however I am constantly receiving this ambiguous error message
{
"error": {
"message": "Error validating verification code.",
"type": "OAuthException",
"code": 100
}
}
I checked the code 100 "Invalid parameter" doesn't means much to me at all.
anyone have had similar problem?
Check you are adding correct code in the url
For example
http://www.xyz.com/?code=AQC399oXame3UKmoAMYnqkZOEXPDNa8ZUFEY9sc6I4YNQnNT-ZgHzpMNnQVZrCUBZVqJRIB1QrXC5xW58_8MNIgQol_PaQvYssUM8OiKjSY5aoqGLBMuCeeHsSqP_mRTd1xiK0iretZcXwMm_27lFYrWFw345Mxod_lfJuB8zI13E8wJUQiArXW_ZlGLNcyxh20#_=_
Code must be
code = AQC399oXame3UKmoAMYnqkZOEXPDNa8ZUFEY9sc6I4YNQnNT-ZgHzpMNnQVZrCUBZVqJRIB1QrXC5xW58_8MNIgQol_PaQvYssUM8OiKjSY5aoqGLBMuCeeHsSqP_mRTd1xiK0iretZcXwMm_27lFYrWFw345Mxod_lfJuB8zI13E8wJUQiArXW_ZlGLNcyxh20
code should not include following in the end
#_=_
If above did not solve the problem
2. redirect_uri must end with /
redirect_uri=http://www.xyz.com/
The following gives some times above mentioned error
redirect_uri=http://www.xyz.com
3. A lso make sure
App on Facebook and Website with Facebook Login are set with same addresss
e.g http://www.xyz.com/
You need to send the user to the Facebook Login page to get a valid code. The code should then be used to get the access_token for the user.
Follow the Authentication Guide.
I also got error message 400, when my app id and secret were wrong (i had messed up develop and production id-s and secrets).
Fixing them (watch also out for the correct host) fixed this problem for me.