Access and change ID content by url?

Asked

Viewed 87 times

0

I’m doing some tests with API of BLOGGER and in the tests I performed I managed to reach a certain point that is to add content to articles via API.

Page where I’m doing my tests:

https://developers.google.com/blogger/docs/3.0/reference/posts/publish

However I would like to make a change to this script.

Behold:

<script src="https://apis.google.com/js/api.js"></script>
<script>
  /**
   * Sample JavaScript code for blogger.posts.insert
   * See instructions for running APIs Explorer code samples locally:
   * https://developers.google.com/explorer-help/guides/code_samples#javascript
   */

  function authenticate() {
    return gapi.auth2.getAuthInstance()
        .signIn({scope: "https://www.googleapis.com/auth/blogger"})
        .then(function() { console.log("Sign-in successful"); },
              function(err) { console.error("Error signing in", err); });
  }
  function loadClient() {
    gapi.client.setApiKey("YOUR_API_KEY");
    return gapi.client.load("https://content.googleapis.com/discovery/v1/apis/blogger/v3/rest")
        .then(function() { console.log("GAPI client loaded for API"); },
              function(err) { console.error("Error loading GAPI client for API", err); });
  }
  // Make sure the client is loaded and sign-in is complete before calling this method.
  function execute() {
    return gapi.client.blogger.posts.insert({
      "blogId": "blogId",
      "resource": {
        "content": "\n&lt;div class=\"separator\" style=\"clear: both; display: none; text-align: center;\"&gt;\n&lt;object class=\"BLOG_video_class\" contentid=\"ID\" height=\"266\" id=\"BLOG_video-ID\" width=\"320\"&gt;&lt;/object&gt;\n&lt;br /&gt;\nID&lt;br /&gt;\n&lt;br /&gt;\n&lt;/div&gt;\n\t"
      }
    })
        .then(function(response) {
                // Handle the results here (response.result has the parsed body).
                console.log("Response", response);
              },
              function(err) { console.error("Execute error", err); });
  }
  gapi.load("client:auth2", function() {
    gapi.auth2.init({client_id: "YOUR_CLIENT_ID"});
  });
</script>

<button onclick="authenticate().then(loadClient)">authorize and load</button>
<button onclick="execute()">execute</button>

The code that the site provided me has a Button to run the script, would run the script by direct url? hosting the script accessing it?

In the content part of the article I would need to send this code the way it is, but only changes the "ID", I would have to edit the code whenever I run it, see that there are 3 ID in this code:

"content": "\n&lt;div class=\"separator\" style=\"clear: both; display: none; text-align: center;\"&gt;\n&lt;object class=\"BLOG_video_class\" contentid=\"**ID**\" height=\"266\" id=\"BLOG_video-**ID**\" width=\"320\"&gt;&lt;/object&gt;\n&lt;br /&gt;\n**ID**&lt;br /&gt;\n&lt;br /&gt;\n&lt;/div&gt;\n\t"

It would be possible to change these direct ID on url execution?

Example:

http://site/meuscritpt.com/?ID= nova-ID

As the ID in url the effect would be the same inside the script.

A while ago I saw something similar here on the site but am not finding more.

  • It is not clear what really needs, very broad the subject, could create a minimal example?

  • I’m trying to access the videos sent to the blogger by url with a direct link like this : https://tudogostoso.blog/make/check/? list=e6dac2f91 I’ll reform the question to see if it becomes clearer.

  • I repeat the question here https://answall.com/questions/414450/acessar-conte%C3%bado-atr%C3%a1ves-de-api-blogger

1 answer

0

Here is the command that you can get a parameter passed by get with javascript

var query = Location.search.Slice(1); var parts = query.split('&'); var data = {}; parts.foreach(Function (part) { var chaveValor = part.split('='); var key = key Value[0]; var value = key Value [1]; date[key] = value; });

console.log(date[name of variable passed by get]);

As described in the link below: How to capture parameters passed by the URL using javascript?

With this you will be able to put the id where you want via Javascript using the variable Data I hope I’ve helped Att

  • I retabled the question here https://answall.com/questions/414450/acessar-conte%C3%bado-atr%C3%a1ves-de-api-blogger

Browser other questions tagged

You are not signed in. Login or sign up in order to post.