I'm shortening my "news" page's long URLs by using this code.
var api_key = 'AIzaSyCNGB0ddmvRkn5h************';
var docURL = document.URL;
function makeRequest() {
var request = gapi.client.urlshortener.url.insert({
'resource': {'longUrl': docURL}
});
request.execute(function(response) {
var newItem = {
url : response.id
}
$(".googlURL").html($("#shareButtons").tmpl({url : response.id , title : $('.newsDetail h3').text()));
});
}
function load() {
gapi.client.setApiKey(api_key);
gapi.client.load('urlshortener', 'v1', makeRequest);
}
this code creates goo.gl URL perfectly.
When someone visit the news details, it creates a shorten url automatically even any url is not created before.
But i would like to see the URLs in my goo.gl panel.
When i visit http://goo.gl/ with my account, i can not see how many URLs created and how many times they visited.
Is there a way to do this?
Thanks
I have found a solution as below about your question. May be that can help you
If you have already created a shortened goo.gl url just type .info at
the end (e.g. goo.gl/url.info)
Related
I am forming a web app in lightning Community Experience Builder using LWC, which already has an URL that carries the domain of my org.
Now I want to handover the URL to users along with an Id appended to its end, such that when the user visits the site I can retrieve the Id from URL using JS.
example,
the original URL: cs-123.aig.lightning.force.com/form
User lands with: cs-123.aig.lightning.force.com/form?userId=123
I must be able to retrieve the userId when the component loads using renderedCallBack or connectedCallBack.
Thanks in advance.
Note:Lightning Navigation Service offered by LWC,doesnt work outside Salesforce,LEX.
Plain JavaScript URLSearchParams should be enough. I have something similar on my project and works ok in community, with LWC embedded on the page.
connectedCallback() {
// Try to read the preselected id from URL
if (window.location.href) {
try {
let url = new URL(window.location.href);
let id = url.searchParams.get('id');
if (id) {
this.userId = id;
}
} catch (e) {
if (console) {
console.log(JSON.stringify(e));
}
}
}
}
I have a google script that sends an email with a Word doc as an attachment. It used to work until google deprecated OAuth 1.0
This is the line that's failing:
var doc = UrlFetchApp.fetch(url+'download/documents/Export?exportFormat=doc&format=doc&id='+ copyId, googleOAuth_('docs',url)).getBlob();
If I remove the second parameter, i.e. function call to OAuth, it should work? Why do I need to authenticate? It should be able to fetch the document using an ID from google drive. It appears to work (because I don't see any errors), however, when I get an email there is a corrupt word doc attachment.
So, I tried implementing OAuth 2.0. But I'm not getting anywhere. Here's my code:
function getDriveService() {
return OAuth2.createService('drive')
.setAuthorizationBaseUrl('https://accounts.google.com/o/oauth2/auth')
.setTokenUrl('https://accounts.google.com/o/oauth2/token')
.setClientId(CLIENT_ID)
.setClientSecret(CLIENT_SECRET)
.setCallbackFunction('authCallback')
.setPropertyStore(PropertiesService.getUserProperties())
.setScope('https://www.googleapis.com/auth/drive')
.setParam('login_hint', Session.getActiveUser().getEmail())
.setParam('access_type', 'offline');
//.setParam('approval_prompt', 'force');
}
function authCallback(request) {
var driveService = getDriveService();
var isAuthorized = driveService.handleCallback(request);
if (isAuthorized) {
return HtmlService.createHtmlOutput('Success! You can close this tab.');
} else {
return HtmlService.createHtmlOutput('Denied. You can close this tab');
}
}
var oauth2Service = getDriveService();
var token = oauth2Service.getAccessToken();
var parameters = { method : 'get',
headers : {'Authorization': 'Bearer '+ token}};
var options =
{
"method" : "get"
};
var resp = UrlFetchApp.fetch('https://docs.google.com/feeds/download/documents/Export?exportFormat=doc&format=doc&id='+ copyId, parameters);
doc = resp.getBlob();
I'm getting a generic error [Access not granted or expired]. All I want is to be able to send an email with an attachment that is a document (format doc or docx) stored from my Google drive. Seems impossible! I'm able to attach this doc as a pdf but NOT a Microsoft document.
Any help will be greatly appreciated!
https://github.com/googlesamples/apps-script-oauth2 - look at setup
...
Have you added OAuth 2.0 in the libraries?
Resources -> Libraries -> then add 'MswhXl8fVhTFUH_Q3UOJbXvxhMjh3Sh48'
I've been messing around with Spring Boot and was pointed at Swagger as a way of documenting my Rest Api.
I managed to get it working except I can't figure out how to customise the index.html file. Whenever I go to http://localhost:8080/index.html it loads the default pet store search bar one and not the one I customised.
I've gone through a tonne of pages online and tried a hundred things but nothing has worked.
Any help would be greatly appreciated.
In my swagger index.html code I have something that looks like this:
$(function () {
var url = window.location.search.match(/url=([^&]+)/);
var pathArray = location.href.split( '/' );
var protocol = pathArray[0];
var host = pathArray[2];
var base = protocol + '//' + host;
if (url && url.length > 1) {
url = url[1];
} else {
url = base + "/api-docs";
}
window.swaggerUi = new SwaggerUi({
url: url,
...
This loads the base, my json code for my swagger api is at /api-docs as you might understand.
I am currenttly developing a Chrome extension and i would like to store the url of a popup window into a string variable.
I am able to get the url via the "document.createElement and variable.appendChild methods, but I can't store it in a string.
This works :
function getLinks(){
var url = document.createElement("p");
chrome.tabs.query({windowType:"popup"}, function (tab){
for(x in tab){
var adresse= document.createTextNode(tab[x].url);
url.appendChild(adresse);
}
});
document.body.appendChild(url);
}
This does not work :
function getLinksbis(){
var url = "1 - ";
chrome.tabs.query({windowType:"popup"}, function (tab){
for(x in tab){
var adresse= tab[x].url;
url = url + adresse;
}
});
document.write(url);
}
Can you help me ? Is it possible to do what i want ?
I want it in a string because I want to add parameters to this url and then shoot it back to the user.
Please excuse my english, I'm french. ;-)
Thanks.
Your code does work, just ensure you have
{
..
"permissions":["tabs"]
..
}
tabs permission in your manifest file.
Output taken after testing
EDIT 1
function getLinksbis() {
var url = "1 - ";
chrome.tabs.query({
windowType: "popup"
}, function (tab) {
for (x in tab) {
var adresse = tab[x].url;
url = url + adresse;
}
document.write(url);
});
}
Move your document.write(url); inside async call back, it is an asynchronous function and final call should be taken after call back is successful.
I get a bunch of different URL from my sources and what I would like is to redirect to the same URL, but with campaign data added to URL (to track the referred clicks).
For example I have these URLs:
www.example.com/category/product/name.html
www.example.com/id_product=5
I want to add at the end the following: utm_source=SOURCE&utm_medium=MEDIUM&utm_campaign=CAMPAIGN
And the URLs to become
www.example.com/category/product/name.html?utm_source=SOURCE&utm_medium=MEDIUM&utm_campaign=CAMPAIGN
www.example.com/id_product=5&utm_source=SOURCE&utm_medium=MEDIUM&utm_campaign=CAMPAIGN
How to I correctly check and cover all the cases if a URL string has parameters, and add mine?
I want to do it in node.js
Thank you
Elaborating on #snkashis, a similar but arguably more elegant solution, again using node's url module, is:
var addQueryParams = function (cleanUrl) {
var obj = url.parse(cleanUrl, true, false);
obj.query['utm_source'] = 'SOURCE';
obj.query['utm_medium'] = 'MEDIUM';
obj.query['utm_campaign'] = 'CAMPAIGN';
delete obj.search; // this makes format compose the search string out of the query object
var trackedUrl = url.format(obj);
return trackedUrl;
};
This works, because url.format first looks for search and, if it can't find it, it composes the query string from the query object
(taken from node url module documentation http://nodejs.org/api/url.html#url_url_format_urlobj )
search will be used in place of query
query (object; see querystring) will only be used if search is absent.
Here is a example showing different scenarios using Node's URL module.
var url = require('url');
var exurls = ["www.example.com/category/product/name.html","www.example.com/id_product=5?hasparam=yes"]
var to_append = "utm_source=SOURCE&utm_medium=MEDIUM&utm_campaign=CAMPAIGN";
for (i=0;i<exurls.length;i++) {
var parsedobj = url.parse(exurls[i],true,false);
//Below checks if param obj is empty.
if (Object.keys(parsedobj.query).length!==0) {
var newpath = parsedobj.href+"&"+to_append;
}
else {
var newpath = parsedobj.href+"?"+to_append;
}
console.log(newpath);
}
Connect will help you:
var connect = require('connect');
var app = connect();
app.use(connect.query());
app.use(function (req, res, next) {
console.log(req.query);
res.end(JSON.stringify(req.query));
});
app.listen(3000);