Set content filter for data connections

The content filtering API allows you to restrict access to certain categories of web content for subscribers accessing the web via their mobile phone. The API works by selecting what content categories should be restricted. Available categories are listed in the proto. No user data is passed to the API consumer and the decision to block is handled within the core platform.

Content Filtering API Overview

Prerequisites

  1. An OAuth 2.0 client
  2. A client access token

Required scope

  • data.content_filtering:read
  • data.content_filtering:write

Code

TIP

You can test our APIs without authorization by targetting sandbox.api.wgtwo.com instead of api.wgtwo.com and removing any authorization from the request/code sample.

Download proto definitions
curl -sL 'https://github.com/working-group-two/wgtwoapis/blob/master/image.bin?raw=true' -o wgtwo.bin
1
export ACCESS_TOKEN="my_client_access_token"
grpcurl -protoset wgtwo.bin \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '
  {
    "filter": {
      "blocked_categories": ["CATEGORY_ADVERTISING"]
    }
  }
  ' \
  api.wgtwo.com:443 \
  wgtwo.data.v1.ContentFilteringService/SetGlobalFilter
1
2
3
4
5
6
7
8
9
10
11
12

Example result

{
"status": "SET_FILTER_STATUS_OK"
}
1
2
3
Install dependencies

Maven

<dependency>
  <groupId>com.wgtwo.api.v1.grpc</groupId>
  <artifactId>consent-events</artifactId>
  <version>1.10.1</version>
</dependency>

search.maven.org/search?q=g:com.wgtwo.api.v1.grpcopen in new window

package com.example.contentfiltering

import com.wgtwo.api.v1.contentFiltering.ContentFiltering.Category
import com.wgtwo.api.v1.contentFiltering.ContentFiltering.SetGlobalFilterRequest
import com.wgtwo.api.v1.contentFiltering.ContentFilteringServiceGrpc
import com.wgtwo.auth.BearerTokenCallCredentials
import io.grpc.ManagedChannelBuilder

/** Use the sandbox environment for testing without authentication */
private val environment = Environment.SANDBOX

private val endpoint = when (environment) {
    Environment.SANDBOX -> "sandbox.api.wgtwo.com"
    Environment.PRODUCTION -> "api.wgtwo.com"
}
private val channel = ManagedChannelBuilder.forAddress(endpoint, 443).build()
private val stub = ContentFilteringServiceGrpc.newBlockingStub(channel).apply {
    /**
     * If you are not using the sandbox, you need to add credentials.
     * The BearerTokenCallCredentials class can be found in our auth library.
     */
    if (environment == Environment.PRODUCTION) {
        this.withCallCredentials(BearerTokenCallCredentials { "MY_CLIENT_ACCESS_TOKEN" })
    }
}

fun main() {
    val request = SetGlobalFilterRequest.newBuilder().apply {
        filterBuilder.apply {
            addBlockedCategories(Category.CATEGORY_ADULT)
            addBlockedCategories(Category.CATEGORY_DRUGS)
        }
    }.build()
    println("Request:\n$request")
    val response = stub.setGlobalFilter(request)
    println("Response:\n$response")

    channel.shutdownNow()
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39

Example result

{
"status": "SET_FILTER_STATUS_OK"
}
1
2
3

Read more