Twitter (OAuth2.0)
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
אחזר מגמות למקום נתון
/**
* Example of using Twitter Application-only authentication from Google Ads Scripts
* Application-only authentication is used where the aspects of the API being
* used do not require impersonating a given Twitter user.
*
* Example usage:
* initializeOAuthClient();
* // Get trends using a woeId to specify location. See:
* // https://developer.yahoo.com/geo/geoplanet/guide/concepts.html
* const results = getTrendsForLocation(44418);
*
* See https://developers.google.com/google-ads/scripts/docs/features/third-party-apis#client_credentials_grant
* for details on configuring this script.
*
* NOTE: This script also requires the OAuth2 library to be pasted at the end,
* as obtained from https://developers.google.com/google-ads/scripts/docs/examples/oauth20-library
*/
// Consumer Key for your application set up at https://apps.twitter.com. See
// 'Keys and Access Tokens' for generating your consumer key.
const TWITTER_CONSUMER_KEY = 'INSERT_CONSUMER_KEY_HERE';
const TWITTER_CONSUMER_SECRET = 'INSERT_CONSUMER_SECRET_HERE';
let authUrlFetch;
// Call this function just once, to initialize the OAuth client.
function initializeOAuthClient() {
if (typeof OAuth2 === 'undefined') {
const libUrl = 'https://developers.google.com/google-ads/scripts/docs/examples/oauth20-library';
throw Error('OAuth2 library not found. Please take a copy of the OAuth2 ' +
'library from ' + libUrl + ' and append to the bottom of this script.');
}
const tokenUrl = 'https://api.twitter.com/oauth2/token';
authUrlFetch = OAuth2.withClientCredentials(
tokenUrl, TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
}
/**
* Retrieves a list of trending topics for a given geographic area of interest.
* @param {string} woeId Geographic location specified in Yahoo! Where On Earth
* format. See https://developer.yahoo.com/geo/geoplanet/guide/concepts.html
* @return {Object} The Trends results object, see:
* https://dev.twitter.com/rest/reference/get/trends/place for details.
*/
function getTrendsForLocation(woeId) {
const url = `https://api.twitter.com/1.1/trends/place.json?id=${woeId}`;
const response = authUrlFetch.fetch(url);
return JSON.parse(response.getContentText());
}
// Paste in OAuth2 library here, from:
// https://developers.google.com/google-ads/scripts/docs/examples/oauth20-library
/**
* Example of using Twitter Application-only authentication from Google Ads Scripts
* Application-only authentication is used where the aspects of the API being
* used do not require impersonating a given Twitter user.
*
* Example usage:
* initializeOAuthClient();
* const results = getTweetsForSearch('Olympics 2016');
* const localResults = getTweetsForSearch('Euro 2016', '51.5085300,-0.1257400,10mi');
*
* See https://developers.google.com/google-ads/scripts/docs/features/third-party-apis#client_credentials_grant
* for details on configuring this script.
*
* NOTE: This script also requires the OAuth2 library to be pasted at the end,
* as obtained from https://developers.google.com/google-ads/scripts/docs/examples/oauth20-library
*/
// Consumer Key for your application set up at https://apps.twitter.com. See
// 'Keys and Access Tokens' for generating your consumer key.
const TWITTER_CONSUMER_KEY = 'INSERT_CONSUMER_KEY_HERE';
const TWITTER_CONSUMER_SECRET = 'INSERT_CONSUMER_SECRET_HERE';
let authUrlFetch;
// Call this function just once, to initialize the OAuth client.
function initializeOAuthClient() {
if (typeof OAuth2 === 'undefined') {
const libUrl = 'https://developers.google.com/google-ads/scripts/docs/examples/oauth20-library';
throw Error('OAuth2 library not found. Please take a copy of the OAuth2 ' +
'library from ' + libUrl + ' and append to the bottom of this script.');
}
const tokenUrl = 'https://api.twitter.com/oauth2/token';
authUrlFetch = OAuth2.withClientCredentials(
tokenUrl, TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET);
}
/**
* Retrieves Tweets for a specific search term.
* @param {string} searchTerm The search term to look for.
* @param {string=} opt_geocode Limit returned Tweets to those from users in a
* location. Specified in the form "latitude,longitude,radius", where radius
* is in either "km" or "mi". e.g. 37.781157,-122.398720,1mi
* @param {string=} opt_mode Optional preference for recent, popular or mixed
* results. Defaults to 'mixed', other options are 'recent' and 'popular'.
* @return {Object} The statuses results object, see:
* https://dev.twitter.com/rest/reference/get/search/tweets for details.
*/
function getTweetsForSearch(searchTerm, opt_geocode, opt_mode) {
const mode = opt_mode || 'mixed';
const url = 'https://api.twitter.com/1.1/search/tweets.json?q=' +
encodeURIComponent(searchTerm) + '&result_type=' + mode;
if (opt_geocode) {
url += 'geocode=' + opt_geocode;
}
const response = authUrlFetch.fetch(url);
return JSON.parse(response.getContentText());
}
// Paste in OAuth2 library here, from:
// https://developers.google.com/google-ads/scripts/docs/examples/oauth20-library
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2024-09-10 (שעון UTC).
[{
"type": "thumb-down",
"id": "missingTheInformationINeed",
"label":"חסרים לי מידע או פרטים"
},{
"type": "thumb-down",
"id": "tooComplicatedTooManySteps",
"label":"התוכן מורכב מדי או עם יותר מדי שלבים"
},{
"type": "thumb-down",
"id": "outOfDate",
"label":"התוכן לא עדכני"
},{
"type": "thumb-down",
"id": "translationIssue",
"label":"בעיה בתרגום"
},{
"type": "thumb-down",
"id": "samplesCodeIssue",
"label":"בעיה בדוגמאות/בקוד"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"סיבה אחרת"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"התוכן קל להבנה"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"התוכן עזר לי לפתור בעיה"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"סיבה אחרת"
}]
{"lastModified": "\u05e2\u05d3\u05db\u05d5\u05df \u05d0\u05d7\u05e8\u05d5\u05df: 2024-09-10 (\u05e9\u05e2\u05d5\u05df UTC)."}
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2024-09-10 (שעון UTC)."]]