File size: 1,737 Bytes
5a32ee0
 
 
 
df50319
5a32ee0
 
 
 
 
 
 
 
 
 
 
 
df50319
5a32ee0
 
 
 
 
 
 
df50319
5a32ee0
 
 
 
 
 
 
 
 
 
 
df50319
5a32ee0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
df50319
5a32ee0
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/**
 * The main Google Apps Script file
 */

// Get data from Line
function getLineData() {
  var lineApiUrl = 'https://api.line.me/v2/oauth/accessToken';
  var options = {
    'method': 'POST',
    'headers': {
      'Content-Type': 'application/x-www-form-urlencoded'
    },
    'payload': 'grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET'
  };
  var response = UrlFetchApp.fetch(lineApiUrl, options);
  var accessToken = JSON.parse(response.getContentText()).access_token;
  
  // Use the access token to get data from Line
  var lineDataUrl = 'https://api.line.me/v2/messages';
  options = {
    'method': 'GET',
    'headers': {
      'Authorization': 'Bearer ' + accessToken
    }
  };
  response = UrlFetchApp.fetch(lineDataUrl, options);
  var lineData = JSON.parse(response.getContentText());
  
  return lineData;
}

// Get image data from Blog
function getBlogImageData() {
  var blogUrl = 'https://example.com/blog';
  var response = UrlFetchApp.fetch(blogUrl);
  var html = response.getContentText();
  var imageUrls = [];
  var regex = /<img.*?src=[\'"](.*?)[\'"].*?>/g;
  var match;
  while ((match = regex.exec(html)) !== null) {
    imageUrls.push(match[1]);
  }
  
  return imageUrls;
}

// Save image data to Google Drive
function saveImageDataToDrive(imageUrls) {
  var driveFolder = DriveApp.getFolderById('YOUR_DRIVE_FOLDER_ID');
  for (var i = 0; i < imageUrls.length; i++) {
    var imageUrl = imageUrls[i];
    var response = UrlFetchApp.fetch(imageUrl);
    var blob = response.getBlob();
    driveFolder.createFile(blob);
  }
}

// Main function
function main() {
  var lineData = getLineData();
  var imageUrls = getBlogImageData();
  saveImageDataToDrive(imageUrls);
}