function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Manohar kumarManohar kumar 

getting an html in Onedrive response

Hi All,

i am trying to upload my files to onedrive.when i try to get the authentication code by calling a url in my get method but coming Status=OK, StatusCode=200.And in the body i am getting an html.pls help any help would be appreciated.And when i put the url in the body it works perfectly.

url i need to call:   https://login.live.com/oauth20_authorize.srf?client_id=Clientkey&scope=wl.signin wl.offline_access onedrive.readwrite&response_type=code&redirect_uri=https://ascmanohar-developer-edition.ap2.force.com/Redirect

my code :

public void GetCode(){
	      http h = new http();
	      httpRequest req = new httpRequest();
	      String Clientkey = EncodingUtil.urlEncode(key,'UTF-8');
             req.setHeader('Content-type', 'application/x-www-form-urlencoded');
	      req.setMethod('GET');
	      string str1 ='wl.signin wl.offline_access onedrive.readwrite';
	      string str2 = EncodingUtil.urlEncode(str1,'UTF-8');
	      
	      string str ='https://login.live.com/oauth20_authorize.srf?client_id='+Clientkey+'&scope='+str2+'&response_type=code&redirect_uri='+redirect_uri;
	      //str = EncodingUtil.urlEncode(str,'UTF-8');
	      system.debug('@@str'+str);
	      req.setEndPoint(str);
	      httpResponse res = h.send(req);
	      system.debug('##res'+res);  
	      system.debug('######'+res.getBody());
	      system.debug('##getlocation##'+res.getHeader('Location'));
      }
 

 

Daniel BallingerDaniel Ballinger
You need to direct the User to that URL rather than trying to do a GET request to it. Once the user has completed the authorization process directly with live.com they will be redirect back to your redirect_uri. The idea is that you never actually process the users credentials.

See OAuth 2.0

Authorization code grant flow