Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

Commit 30735f4

Browse files
author
Eric Koleda
committed
Add sample for Semantics3 and remove unused code in Yelp sample.
1 parent da9f3ee commit 30735f4

File tree

2 files changed

+34
-31
lines changed

2 files changed

+34
-31
lines changed

samples/Semantics3.gs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var API_KEY = '...';
2+
var API_SECRET = '...';
3+
4+
/**
5+
* Authorizes and makes a request to the Semantics3 API.
6+
*/
7+
function run() {
8+
var service = getService();
9+
var query = encodeURIComponent(JSON.stringify({
10+
search: 'iPhone'
11+
}));
12+
var url = 'https://api.semantics3.com/v1/products?q=' + query;
13+
var response = service.fetch(url);
14+
var result = JSON.parse(response.getContentText());
15+
Logger.log(JSON.stringify(result, null, 2));
16+
}
17+
18+
/**
19+
* Configures the service.
20+
*/
21+
function getService() {
22+
return OAuth1.createService('Semantics3')
23+
// Set the consumer key and secret.
24+
.setConsumerKey(API_KEY)
25+
.setConsumerSecret(API_SECRET)
26+
27+
// Manually set the token and secret to the empty string, since the API
28+
// uses 1-legged OAuth.
29+
.setAccessToken('', '');
30+
}

samples/Yelp.gs

Lines changed: 4 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,10 @@ var TOKEN_SECRET = '...';
88
*/
99
function run() {
1010
var service = getService();
11-
if (service.hasAccess()) {
12-
var url = 'https://api.yelp.com/v2/search?term=food&location=San+Francisco';
13-
var response = service.fetch(url);
14-
var result = JSON.parse(response.getContentText());
15-
Logger.log(JSON.stringify(result, null, 2));
16-
} else {
17-
var authorizationUrl = service.authorize();
18-
Logger.log('Open the following URL and re-run the script: %s',
19-
authorizationUrl);
20-
}
21-
}
22-
23-
/**
24-
* Reset the authorization state, so that it can be re-tested.
25-
*/
26-
function reset() {
27-
var service = getService();
28-
service.reset();
11+
var url = 'https://api.yelp.com/v2/search?term=food&location=San+Francisco';
12+
var response = service.fetch(url);
13+
var result = JSON.parse(response.getContentText());
14+
Logger.log(JSON.stringify(result, null, 2));
2915
}
3016

3117
/**
@@ -41,16 +27,3 @@ function getService() {
4127
// console.
4228
.setAccessToken(TOKEN, TOKEN_SECRET);
4329
}
44-
45-
/**
46-
* Handles the OAuth2 callback.
47-
*/
48-
function authCallback(request) {
49-
var service = getService();
50-
var authorized = service.handleCallback(request);
51-
if (authorized) {
52-
return HtmlService.createHtmlOutput('Success!');
53-
} else {
54-
return HtmlService.createHtmlOutput('Denied');
55-
}
56-
}

0 commit comments

Comments
 (0)