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 Working Group Two's core.

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.8.0</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
import com.wgtwo.api.v1.contentFiltering.ContentFiltering.Category
import com.wgtwo.api.v1.contentFiltering.ContentFilteringServiceGrpc
import io.grpc.CallCredentials
import io.grpc.ManagedChannelBuilder
import io.grpc.Metadata
import io.grpc.Status
import java.util.concurrent.Executor
import java.util.function.Supplier

private val isSandboxed = true // Toggle this to go live
private val api = if (!isSandboxed) "api.wgtwo.com" else "sandbox.api.wgtwo.com"
private val channel = ManagedChannelBuilder.forAddress(api, 443).build()
val service = ContentFilteringServiceGrpc.newBlockingStub(channel).apply {
    if (!isSandboxed) { // credentials are needed outside sandbox environment
        this.withCallCredentials(BearerToken { "MY_CLIENT_ACCESS_TOKEN" })
    }
}!!

fun main() {
    try {
        println(service.setGlobalFilter(ContentFiltering.SetGlobalFilterRequest.newBuilder().apply {
            filter = ContentFiltering.Filter.newBuilder().apply {
                addBlockedCategories(Category.CATEGORY_ADULT)
            }.build()
        }.build()))
    } finally {
        channel.shutdownNow()
    }
}

class BearerToken(private val tokenSupplier: Supplier<String>) : CallCredentials() {
    override fun applyRequestMetadata(
        requestInfo: RequestInfo, executor: Executor, metadataApplier: MetadataApplier
    ) {
        executor.execute {
            try {
                val headers = Metadata()
                val token = tokenSupplier.get()
                headers.put(AUTH_HEADER, "Bearer $token")
                metadataApplier.apply(headers)
            } catch (e: Throwable) {
                metadataApplier.fail(Status.UNAUTHENTICATED.withCause(e))
            }
        }
    }

    override fun thisUsesUnstableApi() {}

    companion object {
        private val AUTH_HEADER = Metadata.Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER)
    }
}
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55

Example result

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

Read more