'How to access google analytics data in sigment wise in google app script

My GA has some segments and I would like to access its data/metric into Google app script. Then write it to a google sheet file.

I went through many links on the web, but I did not get any useful documentation for app script.

I went through, the documentation but I did not find anything except an example https://developers.google.com/apps-script/advanced/analytics?authuser=0

The Google app script has some objects, like AnalyticsData, Analytics, for interacting with the services.

But, I did not get any documentation that how can I use these objects to get segment data.

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source