Using RestSharp? Here is how to add ads to your website too.
When building a mobile (or desktop) website that consumes a RESTful backend, there are many options to consume those endpoints. For those comfortable with C# and inclined towards open source solutions RestSharp might be a good API Client for you. It is simple to use and has a great community behind, a good example is Github’s Phil Haack. Here is a short sample on how to use AT&T’s Ads Api and RestSharp to monetize your website.
RestSharp being lightweight (yet robust) provides all the options you need to send and retrieve data from an API. Let’s create am http request for an ad from our API. First make sure you have your OAuth token as we will use it in the example, refer to the Exploring an API article for some tips calling our OAuth service.
Things we will need for our Ads API:
- OAuth Token
- This is the key you will use to make authenticated calls to our API.
- Ads API URL
- Our Ads URL end point.
- This describes what browser will be looking at this ad.
- Content-Type & Accept(Data Format)
- How the ad’s attributes will be encoded over the wire.
- Your Website’s Category
- This describes what type of website will be showing the ads.
- A Unique ID (for each user)
- A unique id for each user that visits your page. Keep in mind the same user can visit several pages in your site.
Creating the API call
Note: this code is for illustrative purposes. Remember to handle errors and optimize to your code base preference when creating your own.
After getting the response back we deserialize the object and now are ready to use the link and image urls in our website. For more information on what JSON object is returned visit our Ad API Docs page. You will see that the size of the ad will be supported by the browser given the user agent we sent.
A good tip on where to place the ads is at the bottom of your site to avoid having the ad too close to your site’s navigation. My preference is to place it inside a DIV tag and set some attributes like the background color if I can.
Here is an example of the CSS for this:
This is what you can expect from the CSS when viewed on a mobile device:
Don’t wait. Add ads today!
RestSharp is only one way of achieving this but there are a lot more options out there. Let me know which one you prefer.