Twitter(OAuth1.0)
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
// User-level Twitter API request
// Requires the OAuth1 library to be pasted into the script.
// https://developers.google.com/google-ads/scripts/docs/examples/oauth10-library
const CONSUMER_KEY = 'INSERT_CONSUMER_KEY_HERE';
const CONSUMER_SECRET = 'INSERT_CONSUMER_SECRET_HERE';
const ACCESS_TOKEN = 'INSERT_ACCESS_TOKEN_HERE';
const ACCESS_SECRET = 'INSERT_ACCESS_SECRET_HERE';
/**
* Retrieves the tweets for the specified Twitter user.
* @param {string} screenName The Twitter name of the user, e.g. 'sundarpichai'
* @return {?Object} The complex response object containing tweets, or null if
* failure. See https://dev.twitter.com/rest/reference/get/statuses/user_timeline
* for structure of this object.
*/
function getTweetsForUser(screenName) {
if (typeof OAuth1 === 'undefined') {
const libUrl = 'https://developers.google.com/google-ads/scripts/docs/examples/oauth10-library';
throw Error('OAuth1 library not found. Please take a copy of the OAuth1 ' +
'library from ' + libUrl + ' and append to the bottom of this script.');
}
const params = {screen_name: screenName};
const authUrlFetch = OAuth1.withAccessToken(CONSUMER_KEY, CONSUMER_SECRET,
ACCESS_TOKEN, ACCESS_SECRET);
const response = authUrlFetch
.fetch('https://api.twitter.com/1.1/statuses/user_timeline.json', params);
const responseText = response.getContentText();
return JSON.parse(responseText);
}
// Paste the OAuth1 library here.
// User-level Twitter API request
// Requires the OAuth1 library to be pasted into the script.
// https://developers.google.com/google-ads/scripts/docs/examples/oauth10-library
const CONSUMER_KEY = 'INSERT_CONSUMER_KEY_HERE';
const CONSUMER_SECRET = 'INSERT_CONSUMER_SECRET_HERE';
const ACCESS_TOKEN = 'INSERT_ACCESS_TOKEN_HERE';
const ACCESS_SECRET = 'INSERT_ACCESS_SECRET_HERE';
/**
* Sends a tweet.
* @param {string} message The message to send.
* @return {?Object} The complex response object with the status of the send
* request. See https://dev.twitter.com/rest/reference/post/statuses/update
* for the structure of this object.
*/
function sendTweet(message) {
if (typeof OAuth1 === 'undefined') {
const libUrl = 'https://developers.google.com/google-ads/scripts/docs/examples/oauth10-library';
throw Error('OAuth1 library not found. Please take a copy of the OAuth1 ' +
'library from ' + libUrl + ' and append to the bottom of this script.');
}
const params = '';
const tweet = message.substring(0, 160);
const options = {method: 'POST', payload: {status: tweet}};
const authUrlFetch = OAuth1.withAccessToken(CONSUMER_KEY, CONSUMER_SECRET,
ACCESS_TOKEN, ACCESS_SECRET);
const response = authUrlFetch
.fetch('https://api.twitter.com/1.1/statuses/update.json', params,
options);
const responseText = response.getContentText();
return JSON.parse(responseText);
}
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2024-08-21(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-08-21(UTC)"],[[["This script enables retrieval of tweets for a specified Twitter user using their screen name and the Twitter API."],["It also allows sending tweets with a message of up to 160 characters through the Twitter API."],["Both functionalities require the OAuth1 library to be included in the script for authentication and authorization with Twitter."],["Before utilizing the script, ensure you replace placeholder values for consumer key, consumer secret, access token, and access secret with your actual Twitter API credentials."]]],[]]