Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- System.LimitException: Maximum stack depth reached: 1001
- global class testFBInt {
- String username = 'username';
- String password = 'password';
- String clientId = 'consumer_id';
- String clientSecret = 'consumer_secret';
- String tokenEndpoint = 'https://test.salesforce.com/services/oauth2/token';
- public testFBInt () {
- this.username = username;
- this.password = password;
- this.clientId = clientId;
- this.clientSecret = clientSecret;
- }
- testFBInt upf = new testFBInt ();
- global void Execute(){
- String sessionId = upf.requestAccessToken();
- System.Debug('@sesionid' + upf.requestAccessToken());
- exInt(sessionId);
- }
- public String requestAccessToken() {
- HttpRequest req = new HttpRequest();
- req.setEndpoint(tokenEndpoint);
- req.setMethod('POST');
- req.setBody(buildHttpQuery(new Map<String, String> {
- 'grant_type' => 'password',
- 'username' => username,
- 'password' => password,
- 'client_id' => clientId,
- 'client_secret' => clientSecret
- }));
- Http http = new Http();
- HttpResponse resp = http.send(req);
- Map<String, Object> m =
- (Map<String, Object>) JSON.deserializeUntyped(resp.getBody());
- return (String) m.get('access_token');
- }
- static String buildHttpQuery(Map<String, String> queryParams) {
- if (queryParams.isEmpty()) {
- return '';
- }
- String[] params = new String[] {};
- for (String k : queryParams.keySet()) {
- String v = EncodingUtil.urlEncode(queryParams.get(k), 'UTF-8');
- params.add(String.format('{0}={1}', new String[] { k, v }));
- }
- return String.join(params, '&');
- }
- @future(callout=true)
- public static void exInt(string sessionId) {
- String dashboardImageURL = 'https://ap4.salesforce.com/servlet/servlet.ChartServer?rsid=.....';
- String base64Data;
- httprequest req = new httprequest();
- req.setEndpoint(dashboardImageURL);
- req.setmethod('GET');
- req.setHeader('Authorization', 'OAuth ' + sessionId);
- http http = new http();
- httpresponse res = http.send(req);
- Blob image = res.getBodyAsBlob();
- base64Data = EncodingUtil.base64Encode(image);
- Document docatt = new Document();
- docatt.Name = 'Chart 1.jpg';
- docatt.Body = EncodingUtil.base64Decode(base64Data);
- docatt.FOLDERID = '00l6F005101pqGi'; //Your folder id
- docatt.IsPublic = true;
- insert docatt;
- System.Debug('@@ doc ' + docatt);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement