← All Apps Scripts templates
/
Get content ideas for social media manager

Get content ideas for social media manager

  1. Create a new Google Sheets file
  2. Create an account on OpenAI, get its API key and paste it in the black box
  3. In order to use the script, you must create a Google Cloud project
  4. Log in to your account if you haven't already.
  5. Create a new GCP (Google Cloud Platform) project.
  6. Once created, make sure to select it
  7. Then activate the Google Sheet API for this GCP project
  8. Then you have to specify the access rights required to use the script:
  9. Enter all required information " * "
  10. And select all the "scopes" of Google Sheet
  11. You will then need to add users, add your Google email
  12. Once set up, go to the GCP project dashboard
  13. And copy the project ID
  14. Finally go back to your Google Sheet
  15. In the menu go to Extensions > Apps Script
  16. Then in the parameters of the script
  17. Click on "Change Project" in the Google Cloud Platform section
  18. Then paste the ID of your new GCP project in the field that appears
  19. And finally click on "Set project".

That's it.

The code to paste in Apps Script inside Google Sheets:


var API_KEY = "";
var BUSINESS_DESCRIPTION = "";
const SS = SpreadsheetApp.getActiveSpreadsheet();
const GLOBAL = SS.getSheetByName("GLOBAL_SETTINGS");
const GPT_MODEL = "text-davinci-003";
function setGlobalSettings() {
  API_KEY = GLOBAL.getRange("B26").getValue();
  BUSINESS_DESCRIPTION = GLOBAL.getRange("B1").getValue();
}
setGlobalSettings();
function getGPTOptions(params) {
    let options = {
      'method': "POST",
      'contentType': 'application/json',
      'headers': {
        Authorization: `Bearer ${API_KEY}`
      },
      'payload': JSON.stringify(params)
    };
    return options;
}
var contentPlanSheet = SS.getSheetByName("GENERATE MONTH CONTENT PLAN");
 
function generateIdeas(jours){
  var description = contentPlanSheet.getRange("F1").getValue();
  var input = "J'ai besoin de générer 1 contenu par jour pendant "+jours+" jours sur mon compte tiktok pour mon entreprise, c'est "+description+". Peux-tu me faire un planning d'idée de contenu sur "+jours+" jours ? Sous la forme d'une liste de bullet point.";
  var params = {
    prompt: input,
    model: GPT_MODEL,
    max_tokens: 3000,
    temperature: 0.5,
    top_p: 1
  };
  var response = UrlFetchApp.fetch('https://api.openai.com/v1/completions', getGPTOptions(params));
  var completion = JSON.parse(response.getContentText())['choices'][0]['text'].replace("\n\n","");
  var ideas = completion.split("\n");
  return ideas;
}
 
function generationContentPlan(){
  setGlobalSettings();
  var annee = contentPlanSheet.getRange("B1").getValue();
  var mois = contentPlanSheet.getRange("B2").getValue();
  var date = new Date(annee+"/"+mois+"/01");
  var ideas = generateIdeas(new Date(annee, mois, 0).getDate());//on envoi le nombre de jour dans le mois
  var firstDay = date.getDay();
  var cell = contentPlanSheet.getRange("C4");
  switch (firstDay) {
    case 0:
      cell = contentPlanSheet.getRange(4,15);
      break;
    case 1:
      cell = contentPlanSheet.getRange(4,3);
      break;
    case 2:
      cell = contentPlanSheet.getRange(4,5);
      break;
    case 3:
      cell = contentPlanSheet.getRange(4,7);
      break;
    case 4:
      cell = contentPlanSheet.getRange(4,9);
      break;
    case 5:
      cell = contentPlanSheet.getRange(4,11);
      break;
    case 6:
      cell = contentPlanSheet.getRange(4,13);
      break;
  }
  Logger.log(cell);
  for (var idea of ideas) {
    let col = cell.getColumn();
    let row = cell.getRow();
    cell.setValue(idea);
    if(col == 15){
      cell = contentPlanSheet.getRange(row+1,3);
    }else{
      cell = contentPlanSheet.getRange(row,col+2);
    }
  }
}
 
function clearCalendar(){
  for (var i = 4; i < 10; i = i+1) {
    for (var j = 3; j <= 15; j = j+2) {
      Logger.log("i = "+i);
      Logger.log("j = "+j);
      contentPlanSheet.getRange(i,j).setValue("");
    }
  }
}

Reach us if the process is unclear or if the script is outdated
Apps Scripts template

Get content ideas for social media manager

Last updated
3/4/2023
Built by
Avatar Placeholder
internal

Similar Apps Script for

Social Media

in Google Sheets

No similar items yet.