Good day all.
Does anyone has a working example how to make Google Plus post through .NET (C#).
I have already tried google and stackoverflow search, but did not manage to find the solution.
I successfully get posts:
public void Post(string text)
{
PlusService plus = new PlusService {Key = "MYVERYSECRETKEY"};
ActivitiesResource ar = new ActivitiesResource(plus, null);
ActivitiesResource.ListRequest list = ar.List("108055870103885325249", new ActivitiesResource.Collection());
ActivityFeed feed = list.Fetch();
string activityKey = "";
foreach (var a in feed.Items)
if (a.Url == "https://plus.google.com/108055870103885325249/posts/EtvvUgn8eKz")
{
activityKey = a.Id;
break;
}
ActivitiesResource.GetRequest get = ar.Get(activityKey);
Activity act = get.Fetch();
var sb = new System.Text.StringBuilder();
sb.AppendLine("Title: " + act.Title);
sb.AppendLine("URL:" + act.Url);
sb.AppendLine("Published:" + act.Published);
sb.AppendLine("By:" + act.Actor.DisplayName);
sb.AppendLine("Annotation:" + act.Annotation);
sb.AppendLine("Content:" + act.Object.Content);
sb.AppendLine("Type:" + act.Object.ObjectType);
sb.AppendLine("# of +1s:" + act.Object.Plusoners.TotalItems);
sb.AppendLine("# of reshares:" + act.Object.Resharers.TotalItems);
}
But I cannot find any method for making posts.
Thanks in advance.
Currently, the Google+ API does not allow writing of posts to a user's activity stream. You can use the moments.insert method in the Google+ REST API to write App Activities to the user's profile, which the user can choose whether to share publicly or to their circles.
You would work with the REST API in a similar manner to other REST APIs in .NET by POSTing to the moments.insert end-point.
This feature is now available to apps that request the https://www.googleapis.com/auth/plus.login scope and specify the type of moments that the app wants to write in the request_visible_actions parameter either in the Google+ Sign-In button or directly in the OAuth query parameters.
Related
I'm trying to make integrate cognito login in to a .net console app with the following code:
public static async Task LoginAsync()
{
var credentials = new AnonymousAWSCredentials();
using var client = new AmazonCognitoIdentityProviderClient(credentials, Amazon.RegionEndpoint.USEast1);
var initAuthRequest = new InitiateAuthRequest();
initAuthRequest.AuthParameters.Add("USERNAME", "myuser#myemail.com");
initAuthRequest.AuthParameters.Add("SRP_A", "3ab487035b1635659eb0f349d2czab124d258b03725x5322138ff24ab5c870311b16585659eb0f349d2ceab124d258b0372555322138ff2");
initAuthRequest.ClientId = "my_amazon_client_id";
initAuthRequest.AuthFlow = AuthFlowType.USER_SRP_AUTH;
var response = await client.InitiateAuthAsync(initAuthRequest);
}
This works perfectly and I get a response with:
SALT
SECRET_BLOCK
SRP_B
USERNAME
USER_ID_FOR_SRP
According to the documentation I have to generate a PASSWORD_CLAIM_SIGNATURE but I don't know how to generate it or what order the cryptographic functions should follow. I have tried to follow all the Amazon documentation but it's not well documented, and the only solutions I found rely on a GetUserPoolId that I don't know where to get it from. I saw another Xamrin.Forms tutorial but it's not exactly following this SRP way that I need.
Any ideas?
Thanks!
The value PASSWORD_CLAIM_SIGNATURE is based on following into one base64-encoded string.
Let K_USER = SHA256_HASH(S_USER)
Let S_USER = (SRP_B - k * gx)(a + ux)
Let x = SHA256_HASH(salt + FULL_PASSWORD)
Let u = SHA256_HASH(SRP_A + SRP_B)
Let k = SHA256_HASH(N + g)
When all MFA challenges are answered, Amazon Cognito responds with a DeviceGroupKey and a unique DeviceKey in the NewDeviceMetadataType field.
For PASSWORD_CLAIM_SECRET_BLOCK, use the value of SECRET_BLOCK.
For TIMESTAMP, include the current time. (For example, Tue Sep 25
00:09:40 UTC 2018.)
Let PASSWORD_CLAIM_SIGNATURE = SHA256_HMAC(K_USER, DeviceGroupKey + DeviceKey + PASSWORD_CLAIM_SECRET_BLOCK + TIMESTAMP), base64-encoded
Ref : Link, Link2, Link3
Can you please show me some c# example for Authorizing and getting instances using Google Compute engine? When I tried authorizing through some of the code that are out there it is always popping up the gmail login page. Is it necessary to use my own login username or can I use the username of the person who created the vm instances on the google cloud platform?
Can you please show me some c# example for Authorizing and getting instances using Google Compute engine?
The following code can help.
private async Task<List<Instance>> GetAllInstances()
{
List<Instance> instanceResult = new List<Instance>();
var service = assign GooglecomputeServiceObject;
InstancesResource instancesResource = new InstancesResource(service);
InstanceList instanceList = await instancesResource.List(your ProjectId, specify_Zone).ExecuteAsync();
if (instanceList.Items != null)
foreach (var item in instanceList.Items)
{
instanceResult.Add(item);
}
return instanceResult;
}
I am building a Asp.net C# application i want to post the user uploaded picture directly to Instagram, but after a quick search i can not found any function in the API somebody help me how to post image on instagram wall by C# code
Below Code I can Get Access Token
private void Authentication()
{
string rest = string.Empty;
GlobusInstagramLib.Authentication.ConfigurationIns config = new GlobusInstagramLib.Authentication.ConfigurationIns("https://instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["consumerKey"], ConfigurationManager.AppSettings["consumerSecret"], ConfigurationManager.AppSettings["callbackurl"], "https://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
oAuthInstagram _api = oAuthInstagram.GetInstance(config);
rest = _api.AuthGetUrl("likes+comments+basic+relationships");
Response.Redirect(rest);
}
// Call back Url
public ActionResult Instagram()
{
string code = (String)Request.QueryString["code"];
oAuthInstagram objInsta = new oAuthInstagram();
GlobusInstagramLib.Authentication.ConfigurationIns configi = new GlobusInstagramLib.Authentication.ConfigurationIns("https://api.instagram.com/oauth/authorize/", ConfigurationManager.AppSettings["consumerKey"], ConfigurationManager.AppSettings["consumerSecret"], ConfigurationManager.AppSettings["callbackurl"], "http://api.instagram.com/oauth/access_token", "https://api.instagram.com/v1/", "");
oAuthInstagram _api = new oAuthInstagram();
_api = oAuthInstagram.GetInstance(configi);
AccessToken access = new AccessToken();
access = _api.AuthGetAccessToken(code);
string accessToken = access.access_token;
string id =access.user.id;
ViewBag.accessToken = accessToken;`enter code here`
ViewBag.Uid = id;
return View();
}
Below Code i have get Access Token and Profile ID
How To Post Image ? some body tall me
You cannot upload photos to Instagram through the API. From Instagram's API documentation https://instagram.com/developer/endpoints/media/:
At this time, uploading via the API is not possible. We made a
conscious choice not to add this for the following reasons:
Instagram is about your life on the go – we hope to encourage photos from within the app.
We want to fight spam & low quality photos. Once we allow uploading from other sources, it's harder to control what comes into the
Instagram ecosystem. All this being said, we're working on ways to
ensure users have a consistent and high-quality experience on our
platform.
I have a website made with ASP.NET webform .NET 4.5 C#. This site contains a forum(homemade by me), parts of this forum needs to be posted to the specific facebook wall(made for this webpage). What I need :
Post just created thread(message) from specific part of the forum to the corsponding facebook wall.
Optional : Sync the forum thread on webpage with message/comments on the specific facebook page
I have looked at these guides :
http://www.codeproject.com/Articles/569920/Publish-a-post-on-Facebook-wall-using-Graph-API
http://www.c-sharpcorner.com/UploadFile/raj1979/post-on-facebook-users-wall-using-Asp-Net-C-Sharp/
But im not sure that this is really the solution for me? I have tried to follow the guide but it does not look the same.
Edit :
dynamic result;
//https://developers.facebook.com/tools/explorer/
//https://developers.facebook.com/tools/access_token/
FacebookClient client = new FacebookClient(ConfigurationManager.AppSettings["FacebookAppToken"]);
//result = client.Get("debug_token", new
//{
// input_token = ConfigurationManager.AppSettings["FacebookAppToken"],
// access_token = ConfigurationManager.AppSettings["FacebookAppToken"]
//});
//result = client.Get("oauth/access_token", new
// {
// client_id = ConfigurationManager.AppSettings["FacebookAppId"],
// client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
// grant_type = "client_credentials",
// //redirect_uri = "http://www.MyDomain.net/",
// //code = ""
// });
result = client.Get("oauth/access_token", new
{
client_id = ConfigurationManager.AppSettings["FacebookAppId"],
client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
grant_type = "client_credentials"
});
client.AccessToken = result.access_token;
result = client.Post("[IdOfFacebookPage]/feed", new { message = "Test Message from app" });
//result.id;
result = client.Get("[IdOfFacebookPage]");
return false;
Approach to post to a facebook wall:
You need to register in facebook developer tools.
Create a app (fill a form).
Download FGT 5.0.480 (Facebook graph toolkit)
Reference FGT dlls in your web application.
FGT has methods to post to facebook wall but needs appId.
Use the app id of your app created in step 2.
To post to an user's wall through facebook, it is only possible through an app.
Try this asp .net app, which will allow you to post in your wall:
https://apps.facebook.com/aspdotnetsample/?fb_source=search&ref=br_tf
This will allow you to envision what you need.
Your app gets an appId with which you need to generate auth token.
Limitation: The user's wall where you want to post should have added the app created at step 2, this is compulsory and there is no work around.
When the user accesses the app for the first time, it automatically asks for permission to post to wall--> the user needs to accept it.
Hope this gives you an idea on how to go about doing this.
You can then post into the user's wall.
For Banshee's below request using Facebook SDK for .NET:
userId - facebook user id, wall to post the message
This user should have added the app created by you in step 1 else it will say unauthorized access.
dynamic messagePost = new ExpandoObject();
messagePost.picture = "http://www.stackoverflow.com/test.png";
messagePost.link = "http://www.stackoverflow.com";
messagePost.name = "This is a test name";
messagePost.caption = "CAPTION 1";
messagePost.description = "Test desc";
messagePost.message = "message"
var fb = new FacebookClient();
dynamic result = fb.Get("oauth/access_token", new {
client_id = "app_id",
client_secret = "app_secret",
grant_type = "client_credentials"
});
fb.AccessToken = result.access_token;
try
{
var postId = fb.Post(userId + "/feed", messagePost);
}
catch (FacebookOAuthException ex)
{
//handle oauth exception
}
catch (FacebookApiException ex)
{
//handle facebook exception
}
You will need an extended token to publish to a wall.. Steps to get extended token is explained well by Banshee..
Edit: How to get extended token by Banshee:
Please follow this post
By creating a extended page token and use it to make the post everything works just fine. See this : How to get Page Access Token by code?
Im surprised that this simple task was so hard to get running and that there was vary little help to get.
Using .NET c# I need to programmatically manage / add subscribers to my lists in aWeber using the API. The process that I am tasked with will be a Windows Service that runs x # of times a day and updates the subscribers at aWeber and the lists that they are in.
So .. all of my research using the aWeber API with .NET has shown me that a signon page at aWeber must be completed in order to receive the oauth_verifier back in the callback URL.
So in summary here are my questions:
Any recommendations on how to accomplish this task using an unattended service?
Has anyone does this?
Any help is greatly appreciated.
Thanks
Emma
1) How to use Aweber .NET SDK to connect with Aweber account [Regular Account - (i.e.) Not the developer's one].
Download .NET SDK for Aweber from https://aweber.codeplex.com/
Ans :- 1) Create a developer account - Visit https://labs.aweber.com/
2) As you have successfully created the account you would see ConsumerKey, ConsumerSecret, & an AppId in your Application.
3) Then for the fist time add the following code.
string ConsumerKey = ConfigurationManager.AppSettings["AWeberConsumerKey"];
string ConsumerSecret= ConfigurationManager.AppSettings["AWeberConsumerSecret"];
Aweber.API api = new Aweber.API(ConsumerKey, ConsumerSecret);
api.CallbackUrl = "http://" + Request.Url.Host + ":" + Request.Url.Port + "/Authorize/Index";
api.get_request_token();
Response.Cookies["oauth_token"].Value = api.OAuthToken;
Response.Cookies["oauth_token_secret"].Value = api.OAuthTokenSecret;
api.authorize();
**Now create An Authorize controller in case of MVC or Authorize.aspx**
string ConsumerKey = ConfigurationManager.AppSettings["AWeberConsumerKey"];
string ConsumerSecret= ConfigurationManager.AppSettings["AWeberConsumerSecret"];
API api = new API(ConsumerKey, ConsumerSecret);
api.OAuthVerifier = Request["oauth_verifier"];
Response.Cookies["access_token"].Value = api.get_access_token();
Account account = api.getAccount();
**Now you can apply your code to create, delete... subscribers to/from the list**
When you run this code first the authorize page will appear where you need to add your Aweber regular account credentials.
Once it's verified then you'll get access to the aweber's(Customer) account.
**But you would not like the authorize page appear always whenever you run your application so you can omit it by doing the following steps.**
1. Use the PHP script provided in http://stackoverflow.com/questions/15378034/how-to-create-an-app-in-aweber
2. Run the above PHP script & you'll get the pair of accesskey & accesssecret.Copy them to your C# code (these are the permanent keys).
3. Initialize the API with this code:
string ConsumerKey = ConfigurationManager.AppSettings["AWeberConsumerKey"];
string ConsumerSecret = ConfigurationManager.AppSettings["AWeberConsumerSecret"];
string accessKey = ConfigurationManager.AppSettings["accessKey"];
string accessSecret = ConfigurationManager.AppSettings["accessSecret"];
Aweber.API api = new Aweber.API(ConsumerKey, ConsumerSecret);
api.OAuthToken = accessKey;
api.OAuthTokenSecret = accessSecret;
Account account = api.getAccount();
**Now we'll code to create subscriber to a particular list**
int listid = int.Parse(ConfigurationManager.AppSettings["ListId"]);
foreach (List list in account.lists().entries)
{
if (list.id == listid) Your List's ID **(Mylist - xxxxxxx)**
{
foreach (Subscriber subscriber in list.subscribers().entries)
{
if (subscriber.email.Equals(objRegModel.EmailID))
{
flag = false;
break;
**Checks whether the similar subscriber exists on the list**
}
else
{
flag = true;
}
}
if (flag == true)
{
BaseCollection<Subscriber> target = list.subscribers();
SortedList<string, object> parameters = new SortedList<string, object>();
parameters.Add("email", objRegModel.EmailID);
parameters.Add("name", objRegModel.FirstName + " " + objRegModel.LastName);
Subscriber subscriber = target.create(parameters);
**This will add the subscriber to the specified list only if does not exist on that list.**
}
}
}
**To Delete a particluar subscriber from the list**
Apply the same logic till Account account = api.getAccount();
To get the EmailID,IP Address etc of the subscribers on the
list.Refer to this link https://labs.aweber.com/docs/permissions
int listid = int.Parse(ConfigurationManager.AppSettings["ListId"]);
foreach (List list in account.lists().entries)
{
if (list.id == listid)
{
foreach (Subscriber subscriber in list.subscribers().entries)
{
We Perform the check whether the email of the subscriber exists on the list or not & accordingly delete it from the list.
if (subscriber.email == eid && subscriber.status != "unconfirmed")
{
try
{
if (subscriber.delete())
{
//Response.Write("Subscriber Successfully Deleted");
}
}
catch (Exception ex)
{
}
}
}
}
}
}