Facebook: Add a second page to a source


#1

I have created a managed source for the Facebook page Redbull. Now I want to update the source as described in http://dev.datasift.com/docs/api/1/sourceupdate to add a second page for CocaCola. But I always get error code 409 (Conflict) with an error message (see below).

Is it possible to fetch two Facebook pages in one source with only one Access token? What I’m doing wrong?

Details:

 
SOURCE-GET-REQUEST:

> curl -X POST https://api.datasift.com/v1/source/get -H 'Authorization: ..."

OUTPUT:

{
  count: 1,
  page: 1,
  pages: 1,
  per_page: 20,
  sources: [
    {
      name: "seppl",
      status: "running",
      parameters: { comments: false, likes: false, posts_by_others: false },
      resources: [
        {
          resource_id: "b6453e04cb774d1eb8b727f197a9b9e8",
          source_id: "fa1478e866204c38acf85dc3144e6740",
          status: "valid",
          parameters: {
            url: "http://www.facebook.com/redbull",
            title: "Red Bull",
            id: "14226545351"
          }
        }
      ],
      created_at: 1391159444,
      id: "fa1478e866204c38acf85dc3144e6740",
      source_type: "facebook_page",
      auth: [
        {
          identity_id: "68154e543e524bc9baddbc1e489da9cc",
          source_id: "fa1478e866204c38acf85dc3144e6740",
          status: "valid",
          parameters: { value: "MyFacebookAppToken" },
          expires_at: 0
        }
      ]
    }
  ]
}

UPDATE-REQUEST:

curl https://api.datasift.com/v1/source/update \
-d ‘id=133376753537407|WQRKTCRheIvSNCQvff97Xl0lMUM’
-d ‘source_type=facebook_page’
-d ‘name=seppl’ \d
-d 'resources= ENCODED AS JSON:
[{“parameters”:{“url”:“http://www.facebook.com/redbull",“title”:"Red Bull”,“id”:“14226545351”}},
// <- old Page, already created

 {"parameters":{"url":"http://www.facebook.com/coca-cola","title":"Coca-Cola","id":"40796308305"}}]           

// <- new Page that I want to add

  • d ‘auth= ENCODED AS JSON:
    [{“parameters”:{“value”:“MyFacebookAppToken”}}]’ \ // <- the same AppToken for both pages?
    -H 'Authorization: …"

OUTPUT:

HTTP/1.1 409 Conflict
A source with the same auth token already exists, or the same resource has been added more than once to this source
Authorization: ...

#2

Hi,

When you call source/get you will get something like:

{
    "name": "",
    "source_type": "facebook_page",
    "status": "running",
    "parameters": [],
    "auth": [
        {
            "identity_id": "0047a9e7f4bb4931b65e7e9bd299ddd1",
            "source_id": "fd2e72e3a7ae40c2a6e86e96381d8165",
            "status": "valid",
            "parameters": {
                "value": "363056350669209|09af1ce9c5d8d23147ec4eeb9a33aac2"
            },
            "expires_at": 1388556000
        }
    ],
    "resources": [
        {
            "resource_id": "d6590d550db94266af6f53884dd65ca4",
            "source_id": "fd2e72e3a7ae40c2a6e86e96381d8165",
            "status": "valid",
            "parameters": {
                "url": "http://www.facebook.com/therollingstones",
                "title": "The Rolling Stones",
                "id": 8305888286
            }
        }
    ],
    "created_at": 1370266044000,
    "id": "fa2e72e3a7ae40c2a6e86e96381d8165"
}

You can see that in the returned 'auth' you get an 'identity_id' and a 'source_id' back, these need to be passed in to the 'auth' parameter when you perform your source/update. This is how the update knows this is an existing token that is in use.

Similarly, when using updates to add new resources you will need to pass the 'resource_id' and the 'source_id' for existing resources that you want to keep to distinguish them from new resources.

Hope that helps, all the steps should be outlined on the source/update page.


#3

Thanks for your reply, but updating a source is still unclear for me:

When I look at the 2nd example in the source/update page http://dev.datasift.com/docs/api/1/sourceupdate , the identity_id (“0047a9e7f4bb4931b65e7e9bd299ddd1”) and “source_id” (“fd2e72e3a7ae40c2a6e86e96381d8165”) doesn’t seem to be used anywhere in the update request.
From where does the id “e25d533cf287ec44fe66e8362f61961f” comes in the example from the source/update page?

curl -X POST https://api.datasift.com/v1/source/update
-d ‘id=e25d533cf287ec44fe66e8362f61961f’

I thought, I could use the ‘source_id’ as id in the source/update-request, is this correct?

In which parameter can I use the ‘identity_id’ argument? (The example only seems to use only the parameters.values, parameters.expires_at in the auth parameter.)


#4

Hi,
So when you do a source get for a specific source you will get some resources back that look something like:


"resources": [
    {
        "resource_id": "d6590d550db94266af6f53884dd65ca4",
        "source_id": "fd2e72e3a7ae40c2a6e86e96381d8165",
        "status": "valid",
        "parameters": {
            "url": "http://www.facebook.com/therollingstones",
            "title": "The Rolling Stones",
            "id": 8305888286
        }
    }
]


This is a page that already exists within the source. If we want to add another page and keep the existing page we will need to use some of the parameters returned above. Say we want to add the giffgaff mobile page and keep the rolling stones page. Our 'resources' parameter in our source/update will become:

[
    {
        "resource_id": "d6590d550db94266af6f53884dd65ca4",
        "source_id": "fd2e72e3a7ae40c2a6e86e96381d8165",
        "status": "valid",
        "parameters": {
            "url": "http://www.facebook.com/therollingstones",
            "title": "The Rolling Stones",
            "id": 8305888286
        }
    },
    {
        "parameters": {
            "url": "http://www.giffgaff.com",
            "title": "giffgaffmobile",
            "id": 287613300716
        }
    }
]

 

Since the giffgaff page is a new resource there is no 'resource_id' or 'source_id' until it has been added. The ID "fd2e72e3a7ae40c2a6e86e96381d8165" is just an example of a source id. A different source ID is used in the example of calling source/update so I can see why this might be confusing, we will get this rectified.

So yes, you are correct, the 'source_id' will be the same as the 'id' in the source/update call but the 'source_id' also needs to be passed in for each existing resource and authentication token.

The identity_id is a value assigned to each auth token, this will need to be passed back when using the source update.


#5

Thanks, your reply makes a lot clear for me.

Some additional questions:

Can I use the same (Facebook) access token in two different sources? What value should I use then in auth.source_id? Or is it only possible to share one access token for multiple pages in one source?

After I decoded the Form-encoded data in some examples, I discovered that in auth.parameters a name attribute can be stored. Can I use the name to store my User-ID (ja normal String with 15 chars)? Can I use different names for the same identitfy_id?


#6

There are two types of Facebook auth tokens, you must have a unique token for each individual managed source.

Facebook user Tokens (The ones generated through the managed source UI) share a rate limit with the Facebook user that created them. Due to this we have started enforcing that all Facebook user tokens need to come from unique Facebook accounts. Since you have multiple Facebook page managed sources linked to the same user via the access token you are getting this error.


Facebook App tokens managed sources will accept app tokens as well as user tokens. App tokens have their own rate limit so there will be no need for creating additional accounts, so this seems like the most elegant solution. Information about generating Facebook app tokens can be found here or on Facebook's official site.

'auth.source_id' will always be the ID of the managed source that token is linked to, so this will always be the same as the 'id' parameter in the update.

The 'name' parameter just relates to the name of the source, incase you want to change the source name via an update.


#7

Ok, thanks again, one unique token for every source. So to fetch multiple Facebook pages with one Facebook App token, I have to create them in just one source.

(@‘name’ parameter: When you search for “fbtoken” at http://dev.datasift.com/docs/api/1/sourcecreate , you see an example where the access token seems to have a different name than the source (“fbtoken” vs “fbp”). I will ignore this name-access-token parameter in the future.)