1"use strict";(self.webpackChunkreddit_ads_api_site=self.webpackChunkreddit_ads_api_site||[]).push([[7920],{15587:(e,s,t)=>{t.r(s),t.d(s,{assets:()=>o,contentTitle:()=>c,default:()=>h,frontMatter:()=>d,metadata:()=>n,toc:()=>a});const n=JSON.parse('{"id":"guides/quick-start/authenticate","title":"Authenticate Your Developer Application","description":"Authenticate your developer app and get your access token to use the Reddit Ads API for custom integrations that interact with Reddit\u2019s ads platform.","source":"@site/versioned_docs/version-v2/guides/quick-start/authenticate.md","sourceDirName":"guides/quick-start","slug":"/guides/quick-start/authenticate","permalink":"/docs/v2/guides/quick-start/authenticate","draft":false,"unlisted":false,"tags":[],"version":"v2","sidebarPosition":2,"frontMatter":{"title":"Authenticate Your Developer Application","sidebar_position":2,"description":"Authenticate your developer app and get your access token to use the Reddit Ads API for custom integrations that interact with Reddit\u2019s ads platform."},"sidebar":"tutorialSidebar","previous":{"title":"Create a Developer Application","permalink":"/docs/v2/guides/quick-start/create-dev-app"}}');var r=t(74848),i=t(28453);const d={title:"Authenticate Your Developer Application",sidebar_position:2,description:"Authenticate your developer app and get your access token to use the Reddit Ads API for custom integrations that interact with Reddit\u2019s ads platform."},c=void 0,o={},a=[{value:"1. Authorize your application",id:"1-authorize-your-application",level:2},{value:"2. Get your access token from the Reddit API",id:"2-get-your-access-token-from-the-reddit-api",level:2},{value:"3. (Optional) Refresh your access token",id:"3-optional-refresh-your-access-token",level:2}];function l(e){const s={a:"a",admonition:"admonition",code:"code",em:"em",h2:"h2",img:"img",li:"li",p:"p",pre:"pre",strong:"strong",table:"table",tbody:"tbody",td:"td",th:"th",thead:"thead",tr:"tr",ul:"ul",...(0,i.R)(),...e.components},{Details:n}=s;return n||function(e,s){throw new Error("Expected "+(s?"component":"object")+" `"+e+"` to be defined: you likely forgot to import, pass, or provide it.")}("Details",!0),(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)(s.p,{children:"You can set up your developer application to gain access to the Reddit API, letting you develop nifty applications and integrations that seamlessly interact with Reddit's ads platform."}),"\n",(0,r.jsx)(s.p,{children:"Before you begin, you should have:"}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"https://business.reddithelp.com/s/article/Create-and-manage-your-Reddit-Ads-account",children:"A Reddit Ads account"}),"."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.a,{href:"./create-dev-app",children:"A developer application"}),". You'll need its app ID and secret."]}),"\n",(0,r.jsx)(s.li,{children:"Access to a terminal application."}),"\n"]}),"\n",(0,r.jsx)(s.h2,{id:"1-authorize-your-application",children:"1. Authorize your application"}),"\n",(0,r.jsxs)(s.p,{children:["Go to your business's ",(0,r.jsx)(s.a,{href:"https://ads.reddit.com/business/developer-applications",children:"developer applications"})," and find your application's app ID. Replace the values in the following link and navigate to it:"]}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{children:"https://www.reddit.com/api/v1/authorize?client_id={{App ID}}&response_type=code&state={{Random String}}&redirect_uri={{Redirect URL}}&duration={{Duration}}&scope={{Scope}}\n"})}),"\n",(0,r.jsxs)(s.ul,{children:["\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"{{App ID}}"}),(0,r.jsx)(s.strong,{children:":"})," The ID of your dev app"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"{{Random String}}"}),(0,r.jsx)(s.strong,{children:":"})," This can be set to any string with no spaces or special characters, like the name of your dev app. This is used to ",(0,r.jsx)(s.a,{href:"https://owasp.org/www-community/attacks/csrf",children:"detect cross-site request forgeries (CSRF)"}),". You can also set a signature for additional security."]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"{{Redirect URL}}"}),(0,r.jsx)(s.strong,{children:":"})," The redirect URL you set for your dev app.","\n",(0,r.jsx)(s.admonition,{type:"note",children:(0,r.jsxs)(s.p,{children:["Don't change ",(0,r.jsx)(s.code,{children:"redirect_uri"})," to ",(0,r.jsx)(s.code,{children:"redirect_url"}),". This parameter must be used so that the application can correctly route mobile and web application redirects."]})}),"\n"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"{{Duration}}"}),(0,r.jsx)(s.strong,{children:":"})," The time limit that this access token will expire. You probably want to set this to ",(0,r.jsx)(s.code,{children:"permanent"}),", but you can set it to ",(0,r.jsx)(s.code,{children:"temporary"})," to make the access code valid for only one hour.","\n",(0,r.jsx)(s.admonition,{type:"note",children:(0,r.jsxs)(s.p,{children:["If you set this to ",(0,r.jsx)(s.code,{children:"temporary"}),", you won't be able to refresh this option."]})}),"\n"]}),"\n",(0,r.jsxs)(s.li,{children:[(0,r.jsx)(s.code,{children:"{{Scope}}"}),(0,r.jsx)(s.strong,{children:":"})," A comma-separated list of the actions performable with the access token.","\n",(0,r.jsx)(s.admonition,{type:"tip",children:(0,r.jsxs)(s.p,{children:["If you'd like your token to access everything in the Reddit Ads API, you can set this to ",(0,r.jsx)(s.code,{children:"adsread,adsconversions,history,adsedit,read"}),".\xa0"]})}),"\n"]}),"\n"]}),"\n",(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:(0,r.jsx)(s.strong,{children:"Scope"})}),(0,r.jsx)(s.th,{children:(0,r.jsx)(s.strong,{children:"Description"})})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"adsconversions"})}),(0,r.jsxs)(s.td,{children:["Post conversion events by enabling access to the ",(0,r.jsx)(s.a,{href:"../../api/conversions-api",children:"Conversions"})," endpoint"]})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"adsedit"})}),(0,r.jsx)(s.td,{children:"Edit ads data"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"adsread"})}),(0,r.jsx)(s.td,{children:"Read advertising data for your account\xa0"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"history"})}),(0,r.jsx)(s.td,{children:"Access submission history"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"read"})}),(0,r.jsx)(s.td,{children:"Read posts and comments for your Reddit user account"})]})]})]}),"\n",(0,r.jsxs)(n,{children:[(0,r.jsxs)("summary",{children:[(0,r.jsx)("strong",{children:"Example:"})," Get link based on credentials"]}),(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:(0,r.jsx)(s.strong,{children:"Field"})}),(0,r.jsx)(s.th,{children:(0,r.jsx)(s.strong,{children:"Value"})})]})}),(0,r.jsxs)(s.tbody,{children:[(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.strong,{children:"App ID"})}),(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"DnvSjQYG9t13lWWOndNqOg"})})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.strong,{children:"Redirect URL"})}),(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"https://www.reddit.com/prefs/apps"})})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.strong,{children:"Scope"})}),(0,r.jsx)(s.td,{children:"Post conversion events with the Conversions API (CAPI)"})]}),(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.strong,{children:"Link"})}),(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"https://www.reddit.com/api/v1/authorize?client_id=DnvSjQYG9t13lWWOndNqOg&response_type=code&state=sgtm-capi&redirect_uri=https://www.reddit.com/prefs/apps&duration=permanent&scope=adsconversions"})})]})]})]})]}),"\n",(0,r.jsxs)(s.p,{children:["Check that the username listed matches the account you want to authorize the app. If the username is correct, select ",(0,r.jsx)(s.em,{children:"Allow"}),"."]}),"\n",(0,r.jsx)(s.p,{children:(0,r.jsx)(s.img,{alt:"Check your username",src:t(17194).A+"",width:"1600",height:"770"})}),"\n",(0,r.jsx)(s.admonition,{type:"important",children:(0,r.jsx)(s.p,{children:"If an unexpected username is displayed, you're in an active Reddit session. To fix this, log out of your account, log into the correct account, then revisit the URL."})}),"\n",(0,r.jsxs)(s.p,{children:["You will be sent to the redirect URL that you provided earlier. The URL in your address bar will have 2 query parameters: the state and the code. Copy and record the code value and remove the ",(0,r.jsx)(s.code,{children:"#_"})," characters at the end of the value, if any."]}),"\n",(0,r.jsx)(s.admonition,{type:"important",children:(0,r.jsx)(s.p,{children:"This code should be used within the next ten minutes and only once per authorization."})}),"\n",(0,r.jsx)(s.p,{children:(0,r.jsx)(s.img,{alt:"Copy the code",src:t(75010).A+"",width:"1600",height:"142"})}),"\n",(0,r.jsxs)(n,{children:[(0,r.jsxs)("summary",{children:[(0,r.jsx)("strong",{children:"Example:"})," Find code value from redirect URL"]}),(0,r.jsxs)(s.table,{children:[(0,r.jsx)(s.thead,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.th,{children:"Redirect URL"}),(0,r.jsx)(s.th,{children:"Code value"})]})}),(0,r.jsx)(s.tbody,{children:(0,r.jsxs)(s.tr,{children:[(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"https://notarealbrand.myshopify.com/oauth/callback?state=my-state&code=Ve49meZ9oh3lZFY35CEizm3jTsfJeA#_"})}),(0,r.jsx)(s.td,{children:(0,r.jsx)(s.code,{children:"Ve49meZ9oh3lZFY35CEizm3jTsfJeA"})})]})})]})]}),"\n",(0,r.jsx)("p",{}
1),"\n",(0,r.jsx)(s.h2,{id:"2-get-your-access-token-from-the-reddit-api",children:"2. Get your access token from the Reddit API"}),"\n",(0,r.jsx)(s.p,{children:"Open a terminal window and execute the following cURL command with your noted values:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"curl -X POST https://www.reddit.com/api/v1/access_token \\\n\xa0\xa0\xa0\xa0\xa0-H 'content-type: application/x-www-form-urlencoded' \\\n\xa0\xa0\xa0\xa0\xa0-A '{{Name}}' \\\n\xa0\xa0\xa0\xa0\xa0-u '{{App ID}}:{{Secret}}' \\\n\xa0\xa0\xa0\xa0\xa0-d 'grant_type=authorization_code&code={{Redirect Code}}&redirect_uri={{Redirect URL}}'\n"})}),"\n",(0,r.jsxs)(n,{children:[(0,r.jsxs)("summary",{children:[(0,r.jsx)("strong",{children:"Example:"})," Get access token"]}),(0,r.jsxs)("table",{children:[(0,r.jsxs)("tr",{children:[(0,r.jsx)("th",{children:"Field"}),(0,r.jsx)("th",{children:"Value"})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:(0,r.jsx)("strong",{children:"Name"})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.code,{children:"SGTM-CAPI"})})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:(0,r.jsx)("strong",{children:"App ID"})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.code,{children:"DnvSjQYG9t13lWWOndNqOg"})})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:(0,r.jsx)("strong",{children:"Secret"})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.code,{children:"Ucr7PXIWe_OK_vAsrE0J3kvDJ0faww"})})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:(0,r.jsx)("strong",{children:"Redirect Code"})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.code,{children:"QGRMgx3l54x0s8NT_WdcuSt_Adi9nA"})})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:(0,r.jsx)("strong",{children:"Redirect URL"})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.code,{children:"https://www.reddit.com/prefs/apps"})})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:(0,r.jsx)("strong",{children:"Code"})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"curl -X POST https://www.reddit.com/api/v1/access_token \\\n -H 'content-type: application/x-www-form-urlencoded' \\\n -A 'SGTM-CAPI' \\\n -u 'DnvSjQYG9t13lWWOndNqOg:Ucr7PXIWe_OK_vAsrE0J3kvDJ0faww' \\\n -d 'grant_type=authorization_code&code=QGRMgx3l54x0s8NT_WdcuSt_Adi9nA&redirect_uri=https://www.reddit.com/prefs/apps'\n"})})})]})]})]}),"\n",(0,r.jsx)(s.p,{children:"If successful, you will receive a response that looks like this:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'{\n\xa0\xa0\xa0\xa0"access_token": {{Access token}},\n\xa0\xa0\xa0\xa0"token_type": "bearer",\n\xa0\xa0\xa0\xa0"expires_in": {{Expiration time in Unix epoch}},\n\xa0\xa0\xa0\xa0"refresh_token": {{Refresh token}},\n\xa0\xa0\xa0\xa0"scope": {{Scope string}}\n}\n'})}),"\n",(0,r.jsxs)(s.p,{children:["Record the value for ",(0,r.jsx)(s.code,{children:"access_token"})," and ",(0,r.jsx)(s.code,{children:"refresh_token"}),". You'll use ",(0,r.jsx)(s.code,{children:"access_token"})," to access the Reddit Ads API for either one hour (3600) or one day (86400), whichever is listed for the value for ",(0,r.jsx)(s.code,{children:"expires_in"}),"."]}),"\n",(0,r.jsx)(s.h2,{id:"3-optional-refresh-your-access-token",children:"3. (Optional) Refresh your access token"}),"\n",(0,r.jsx)(s.p,{children:"You can use an active access token to maintain continuous access to the API without requiring re-authentication.\xa0"}),"\n",(0,r.jsx)(s.p,{children:"To refresh your token, open a terminal window and execute the following cURL command with your noted values:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"curl -X POST https://www.reddit.com/api/v1/access_token \\\n\xa0\xa0\xa0\xa0\xa0-A '{{Name}}' \\\n\xa0\xa0\xa0\xa0\xa0-u '{{App ID}}:{{Secret}}' \\\n\xa0\xa0\xa0\xa0\xa0-d 'grant_type=refresh_token&refresh_token={{Refresh token}}'\n"})}),"\n",(0,r.jsxs)(n,{children:[(0,r.jsxs)("summary",{children:[(0,r.jsx)("strong",{children:"Example:"})," Refresh token"]}),(0,r.jsxs)("table",{children:[(0,r.jsxs)("tr",{children:[(0,r.jsx)("th",{children:"Field"}),(0,r.jsx)("th",{children:"Value"})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:(0,r.jsx)("strong",{children:"Name"})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.code,{children:"SGTM-CAPI"})})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:(0,r.jsx)("strong",{children:"App ID"})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.code,{children:"kmY1CRszT3obFwYeU3uuEw"})})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:(0,r.jsx)("strong",{children:"Secret"})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.code,{children:"rTBVO3UirF-fcwvlMNellSxqkd3wSQ"})})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:(0,r.jsx)("strong",{children:"Refresh Token"})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.code,{children:"90773738700875-TEhY
1siu7TO6A6PIWuiweSH_PBW96lw"})})]}),(0,r.jsxs)("tr",{children:[(0,r.jsx)("td",{children:(0,r.jsx)("strong",{children:"Code"})}),(0,r.jsx)("td",{children:(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-bash",children:"curl -X POST https://www.reddit.com/api/v1/access_token \\\n -A 'SGTM-CAPI' \\\n -u 'kmY1CRszT3obFwYeU3uuEw:rTBVO3UirF-fcwvlMNellSxqkd3wSQ' \\\n -d 'grant_type=refresh_token\n refresh_token=90773738700875-TEhYsiu7TO6A6PIWuiweSH_PBW96lw'\n"})})})]})]})]}),"\n",(0,r.jsx)(s.p,{children:"If successful, you will receive a response that looks like this:"}),"\n",(0,r.jsx)(s.pre,{children:(0,r.jsx)(s.code,{className:"language-json",children:'{\n\xa0\xa0\xa0\xa0"access_token": {{Access token}},\n\xa0\xa0\xa0\xa0"token_type": "bearer",\n\xa0\xa0\xa0\xa0"expires_in": {{Expiration time in Unix epoch}},\n\xa0\xa0\xa0\xa0"refresh_token": {{Refresh token}},\n\xa0\xa0\xa0\xa0"scope": {{Scope string}}\n}\n'})}),"\n",(0,r.jsxs)(s.p,{children:["Record the value for ",(0,r.jsx)(s.code,{children:"access_token"})," and ",(0,r.jsx)(s.code,{children:"refresh_token"}),". You'll use ",(0,r.jsx)(s.code,{children:"access_token"})," to access the Reddit Ads API for either one hour (3600) or one day (86400), whichever is listed for the value for ",(0,r.jsx)(s.code,{children:"expires_in"}),"."]})]})}function h(e={}){const{wrapper:s}={...(0,i.R)(),...e.components};return s?(0,r.jsx)(s,{...e,children:(0,r.jsx)(l,{...e})}):l(e)}},17194:(e,s,t)=>{t.d(s,{A:()=>n});const n=t.p+"assets/images/check-username-730d8ba6fa4b8147f23abe916991eb59.webp"},75010:(e,s,t)=>{t.d(s,{A:()=>n});const n=t.p+"assets/images/copy-code-7529e9db824d1ea0b85628912f583ca6.webp"}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.