1

Im trying to create a JSON request and I have the below script, for some reason I don't get a response. Can anyone help with this?

I haver my token but I have no idea where I need to put it?

    <script>
    $.ajax(
        'https://data.brightcove.com/analytics-api/videocloud/accounts/867903724001/report/?dimensions=video&format=json', {
            type: 'GET',
            dataType: 'json',
            beforeSend: function(xhr) {
                xhr.setRequestHeader("Authorization", "Bearer $token")
            },
            complete: function(resp) {
                console.log(resp);
            },
            error: function(jqXHR, textStatus, errorThrown) {
                console.log(textStatus);
            }
        }
    );
</script>

2 Answers 2

1
 $.ajax({
        url: 'https://data.brightcove.com/analytics-api/videocloud/accounts/867903724001/report/?dimensions=video&format=json',
      dataType: 'JSONP',
     beforeSend: function(xhr) {
                xhr.setRequestHeader("Authorization", "Bearer $token")
            },
      success: function(data){
        console.log(data)
      },
     error: function(jqXHR, textStatus, errorThrown)   {
                    console.log(textStatus);
                }

    })

Change datatype json to jsonp. Since you trying to access cross domain you have to use jsop.

Sign up to request clarification or add additional context in comments.

7 Comments

I can change the data type to JSONP, but where to I put my access token?
U mentioned in right place. It should in beforesend method.
my access token looks like this dewfdew8f7dew89d7ew8c798c7ew8c9ew7c98e7698ew6c8ec9ewc8ew. Where do I put that?
u have to add it in the url. without adding the access token u wont gen access to brightcove api
|
0

You can use this script in the html file

<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/qs/6.9.4/qs.js"></script>

After requiring this script you can write your own javascript function and it will work.

brightcoveClientId: Pass dynamic brightcove client id. brightcoveClientSecret: Pass dynamic brightcove secret.

      async  function brightCove(params) {
          const config = {
          url: 'https://oauth.brightcove.com/v4/access_token',
          method: 'post',
          data: Qs.stringify({
            grant_type: 'client_credentials',
            client_id: brightcoveClientId,
            client_secret: brightcoveClientSecret,
          })
        };
        const bearerToken = await axios(config);
        const getPlayableUrl = await axios.get(`https://cms.api.brightcove.com/v1/accounts/${brightcoveAccountId}/videos/${embededCode}/sources`,
          {
            "headers": {
              "content-type": "application/x-www-form-urlencoded",
              "authorization": `Bearer ${bearerToken.data.access_token}`
            }
          });
        }

It is working fine for me.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.