Is it possible to post new blog entry using service account and ServiceAccountCredential based upon P12 keys

John Walton <[email protected]>
Newsgroups gmane.comp.web.blogger.api
Message-ID <[email protected]>
This question, or variations of it, has been posted by very many group 
members over last few years, with no positive definitive answer!

I have an application that automatically makes small nightly posts to my 
own blog. Worked fine for years, until about June 2015, when the api ceased 
to be supported. So I started converting to API V3 (platform is c#). After 
a few false starts, I have now got as far as creating a  
ServiceAccountCredential, and then a BloggerService. I use a ".p12" file 
previously created using Google Developers Console for the Compute Engine 
default service account (as recommended by Google Wizard!). When it 
executes (under Visual Studio 2015) , I see:





*Google.Apis.Requests.RequestErrorWe're sorry, but you don't have 
permission to access this resource. [403]Errors [ Message[We're sorry, but 
you don't have permission to access this resource.] Location[ - ] 
Reason[forbidden] Domain[global]]*

I have spent days trying to find solution. I know that a few years ago it 
was stated that Blogger Service Account were not supported. But the Google 
wizard
 even tells me that I can use the "Compute Engine default service account "!

So are service accounts supported please? If they are not, then all the web 
pages that describe this feature for Blogger should be removed, and the 
wizard updated!!!

Any suggestions for another solution?. All I want to do is make posts 
without any "user" login etc, using my own data; very simple.

Here is code:

// 28 Jan 2016

using System;

//using System.Collections.Generic;

//using System.Linq;

using System.Web;

using System.Web.UI;

//using System.Web.UI.WebControls;

using Google.Apis.Blogger.v3;

using Google.Apis.Auth.OAuth2;

//using System.Threading;

//using Google.Apis.Util.Store;

using Google.Apis.Services;

using System.Security.Cryptography.X509Certificates;

//using System.IO;


namespace WebApplication5

{

public partial class _Default : Page

{

protected void Page_Load(object sender, EventArgs e)

{

string KeyID = "9acb88a8ab58c732733396741f4655fa120ac583";

string blogId = "5062668863072692683";

            

// Compute Engine default service account

string serviceAccountEmail = 
"[email protected]";

string keyp12 = "DanceWebUK-1111111111111.p12";

            string[] scopes = new string[] { BloggerService.Scope.Blogger };


var certificate = new X509Certificate2(Server.MapPath(keyp12), "notasecret", 
X509KeyStorageFlags.Exportable);

ServiceAccountCredential m_credential = new ServiceAccountCredential(

new ServiceAccountCredential.Initializer(serviceAccountEmail)

{

Scopes = scopes

}.FromCertificate(certificate));

            

Trace.Write(" Page_Load", "credential: " + m_credential);


var service = new BloggerService(new BaseClientService.Initializer()

{

HttpClientInitializer = m_credential,

ApplicationName = "Blogger"

});

Google.Apis.Blogger.v3.Data.Post post = new Google.Apis.Blogger.v3.Data.Post
();

post.Content = "Test 2016 " + DateTime.Now.ToString();

post.Kind = "blogger#post";

post.Title = "Test Post";

var postsInsertAction = service.Posts.Insert(post, blogId);

Google.Apis.Blogger.v3.Data.Post post2 = postsInsertAction.Execute();

            

Trace.Write("", "done");


}

}

}


-- 
You received this message because you are subscribed to the Google Groups "Blogger Developer Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/bloggerdev.
For more options, visit https://groups.google.com/d/optout.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.