Last active
February 28, 2023 19:14
-
-
Save SourcingDenis/09f5c20b2a4bd1a21461f92400e0a1ac to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function searchGitHubProfile() { | |
var spreadsheet = SpreadsheetApp.getActiveSpreadsheet(); | |
var sheet = spreadsheet.getActiveSheet(); | |
var selectedRange = sheet.getActiveRange(); | |
var searchQueryValues = selectedRange.getValues(); | |
var accessToken = 'INSERT_YOUR_GITHUB_API_KEY'; | |
var headers = { | |
'Authorization': 'Bearer ' + accessToken, | |
'User-Agent': 'GoogleAppsScript' | |
}; | |
var options = { | |
'method': 'get', | |
'headers': headers | |
}; | |
var results = []; | |
for (var i = 0; i < searchQueryValues.length; i++) { | |
var searchQuery = searchQueryValues[i][0]; | |
var searchUrl = 'https://api.github.com/search/users?q=' + searchQuery; | |
var response = UrlFetchApp.fetch(searchUrl, options); | |
var json = response.getContentText(); | |
var data = JSON.parse(json); | |
var items = data.items; | |
if (items && items.length > 0) { | |
var firstResult = items[0]; | |
var link = firstResult.html_url; | |
results.push([link]); | |
} else { | |
results.push(["No profile found"]); | |
} | |
} | |
selectedRange.offset(0, 1).setValues(results); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function searchLinkedInProfiles() { | |
var sheet = SpreadsheetApp.getActiveSheet(); | |
var range = sheet.getActiveRange(); | |
var values = range.getValues(); | |
var apiKey = 'INSERT_YOUR_API_KEY'; | |
var cx = 'INSERT_YOUR_CX_KEY'; | |
values.forEach(function(row, rowIdx) { | |
row.forEach(function(cell, colIdx) { | |
var query = cell; | |
var url = 'https://www.googleapis.com/customsearch/v1?key=' + apiKey + '&cx=' + cx + '&q=' + query + '&num=1&lr=lang_en&siteSearch=linkedin.com'; | |
var response = UrlFetchApp.fetch(url); | |
var json = JSON.parse(response.getContentText()); | |
if (json.searchInformation.totalResults > 0) { | |
var link = json.items[0].link; | |
sheet.getRange(range.getRow() + rowIdx, range.getColumn() + colIdx + 1).setValue(link); | |
} | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment