c# program to call Google+ API and Custom Search API from Google - c#

Can you please tell me via a code sample how I can write a C# program that will call
the Google+ API and Custom Search API of Google.
I know there is a brief description of it on :::::
URL:https://developers.google.com/+/api/
URL:https://developers.google.com/custom-search/v1/using_rest
URL:http://code.google.com/p/google-api-dotnet-client/wiki/OAuth2
But the process mentioned in the links in doing the above as given in the documentation is
not very clear.
Is there a simple illustration through C# code that I can use to call Google+ API and Custom
Search API?

The Google API Dotnet Client project contains .NET wrappers form most of Google's APIs, including Google+.
They do have several examples but not for all of their APIs, yet.
A Google+ example from their page to query for public activities is:
CommandLine.EnableExceptionHandling();
CommandLine.DisplayGoogleSampleHeader("PlusService API");
// Create the service.
var objService= new PlusService();
objService.Key = ""; //put in user key.
var acts = objService.Activities.Search();
acts.Query = "super cool";
acts.MaxResults = 10;
var searchResults = acts.Fetch();
if (searchResults.Items != null)
{
foreach (Activity feed in searchResults.Items)
{
//extract any property of uer interest
CommandLine.WriteResult(feed.Title, feed.Actor);
}
}

Related

How to remove Posted Via Graph Api when posting on Facebook

I am posting to Facebook using c#
private static void PostToPage(string message)
{
var fb = new FacebookClient("My Little Pony Facebook token is Magic");
var argList = new Dictionary<string, object>();
argList["message"] = message;
fb.Post("feed", argList);
}
But I get this Posted via Graph Api Explorer on the face book wall (check this IMAGELINK). Any way I can customise this to make it more personal like Posted By user
See this SO Discussion:
Replace "via Graph API Explorer" label by my application name
If it says 'via Graph API Explorer' on the posts your app makes you're
using the access token you retrieved when you were testing the API
using the Graph API Explorer tool, not one produced by your own app

Google Custom Search .NET API Compile issue with Fetch method

I am attempting to use the Google CustomSearch API for .NET using sample code from the following locations:
Steps for using Google custom search API in .NET
How can I do a search with Google Custom Search API for .NET?
http://astrocoder.com/search-using-google-custom-search/
The basic code in it's simplest form looks like:
string apiKey = "my-api-key";
string cseKey = "my-cse-id";
string query = "search query";
var bcsi = new BaseClientService.Initializer { ApiKey = apiKey };
var css = new CustomsearchService(bcsi);
var listRequest = css.Cse.List(query);
listRequest.Cx = cseKey;
Search search = listRequest.Fetch();
However, when I attempt to compile this, I am getting the following error:
'Google.Apis.Customsearch.v1.CseResource.ListRequest' does not
contain a definition for 'Fetch' and no extension method 'Fetch'
accepting a first argument of type
'Google.Apis.Customsearch.v1.CseResource.ListRequest' could be found
As far as I can tell, I have all of the required library files (I used NuGet to install the Google APIs). When I view the API documentation, I do not see a Fetch() method, however, all of the sample code I have been able to find shows the listRequest.Fetch() method call.
https://developers.google.com/resources/api-libraries/documentation/customsearch/v1/csharp/latest/classGoogle_1_1Apis_1_1Customsearch_1_1v1_1_1CseResource_1_1ListRequest-members.html
Instead of using Fetch() you can use the following.
Search search = listRequest.Execute();
The fetch() api has been replaced after version 1.4 but the sample code has not been updated yet.

How do I get Google Calendar feed from user's access token?

Using OAuth I do get access token from Google. The sample that comes with Google and even this one:
http://code.google.com/p/google-api-dotnet-client/source/browse/Tasks.SimpleOAuth2/Program.cs?repo=samples
show how to use Tasks API. However, I want to use Calendar API. I want to get access to user's calendar. Can anybody tell me how do I do that?
Take a look at the samples:
Getting Started with the .NET Client Library
On the right side of the page linked above there is a screen shot showing the sample projects contained in the Google Data API solution. They proofed to be very helpful (I used them to start my own Google Calendar application).
I recommend keeping both your own solution and the sample solution open. This way you can switch between the examples and your own implementation.
I also recommend to use the NuGet packages:
Google.GData.AccessControl
Google.GData.Calendar
Google.GData.Client
Google.GData.Extensions
and more ...
This way you easily stay up to date.
Sample to get the users calendars:
public void LoadCalendars()
{
// Prepare service
CalendarService service = new CalendarService("Your app name");
service.setUserCredentials("username", "password");
CalendarQuery query = new CalendarQuery();
query.Uri = new Uri("https://www.google.com/calendar/feeds/default/allcalendars/full");
CalendarFeed calendarFeed = (CalendarFeed)service.Query(query);
Console.WriteLine("Your calendars:\n");
foreach(CalendarEntry entry in calendarFeed.Entries)
{
Console.WriteLine(entry.Title.Text + "\n");
}
}

Simple C# Evernote API OAuth example or guide?

Anybody know where I can find a simple example C# code example? Apparently really tough to find.
I'm just starting out, got my Developer key.
Initial (really noob question/presumption) - -Can (should/must) my solution be a web service client? No new libraries I need to install in .Net right?
Basically, as a test, I want to be able to securely present a single note from a private notebook in html similar to what the Everfort export in html looks like on a outside WebSite.
Many Thanks in Advance!
You should start by downloading our API ZIP from http://www.evernote.com/about/developer/api/. You'll find C# client sample code in /sample/csharp. This sample code demonstrates using the Evernote API from a desktop application that authenticates using username and password.
I am not sure if you ever got this working, but I was playing around with Evernote, OpenAuth and C# this morning and managed to get it all working. I have put together a blog post / library explaining the experience and outlining how to do it with MVC here - http://www.shaunmccarthy.com/evernote-oauth-csharp/ - it uses the AsyncOAuth library: https://github.com/neuecc/AsyncOAuth
I wrote a wrapper around AsyncOAuth that you might find useful here: https://github.com/shaunmccarthy/AsyncOAuth.Evernote.Simple
One prickly thing to be aware of - the Evernote Endpoints (/oauth and /OAuth.action) are case sensitive
// Download the library from https://github.com/shaunmccarthy/AsyncOAuth.Evernote.Simple
// Configure the Authorizer with the URL of the Evernote service,
// your key, and your secret.
var EvernoteAuthorizer = new EvernoteAuthorizer(
"https://sandbox.evernote.com",
"slyrp-1234", // Not my real id / secret :)
"7acafe123456badb123");
// First of all, get a request token from Evernote - this causes a
// webrequest from your server to Evernote.
// The callBackUrl is the URL you want the user to return to once
// they validate the app
var requestToken = EvernoteAuthorizer.GetRequestToken(callBackUrl);
// Persist this token, as we are going to redirect the user to
// Evernote to Authorize this app
Session["RequestToken"] = requestToken;
// Generate the Evernote URL that we will redirect the user to in
// order to
var callForwardUrl = EvernoteAuthorizer.BuildAuthorizeUrl(requestToken);
// Redirect the user (e.g. MVC)
return Redirect(callForwardUrl);
// ... Once the user authroizes the app, they get redirected to callBackUrl
// where we parse the request parameter oauth_validator and finally get
// our credentials
// null = they didn't authorize us
var credentials = EvernoteAuthorizer.ParseAccessToken(
Request.QueryString["oauth_verifier"],
Session["RequestToken"] as RequestToken);
// Example of how to use the credential with Evernote SDK
var noteStoreUrl = EvernoteCredentials.NotebookUrl;
var noteStoreTransport = new THttpClient(new Uri(noteStoreUrl));
var noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
var noteStore = new NoteStore.Client(noteStoreProtocol);
List<Notebook> notebooks = client.listNotebooks(EvernoteCredentials.AuthToken);
http://weblogs.asp.net/psteele/archive/2010/08/06/edamlibrary-evernote-library-for-c.aspx might help. As the author states it just bundles some and fixes some. Haven't tried it myself but thought I'd mention for a possibly easier way to get started. Possibly.
This might help too...found it using the Way Back Machine since the original blog site was offline.
https://www.evernote.com/pub/bluecockatoo/Evernote_API#b=bb2451c9-b5ff-49bb-9686-2144d984c6ba&n=c30bc4eb-cca4-4a36-ad44-1e255eeb26dd
The original blog post: http://web.archive.org/web/20090203134615/http://macrolinz.com/macrolinz/index.php/2008/12/
Scroll down and find the post from December 26 - "Get it while it's hot..."

Making telephone call from ASP.NET application

I have a requirement that we need to make a telephone call using ASP.NET application.
Our ASP.NET application is used in call center. Currently, they make a call to customer manually. Now, the call should go from our application by clicking the phone number link and starts recording the conversation between the agent (application user) and customer.
What all would be the hardware requirements for the above scenario?
How can we implement telephone calling in asp.net application and what are the required components to implement the same?
Nexmo offers a range of cloud communication APIs including Voice API that allows you to fulfil this requirement.
All you need is to install the Nuget package:
Install-Package Nexmo.Csharp.Client
Then use the Call class:
Call.Do(new Call.CallCommand
{
to = new[]
{
new Call.Endpoint
{
type = "phone",
number = NEXMO_TO_NUMBER
}
from = new Call.Endpoint
{
type = "phone",
number = NEXMO_FROM_NUMBER
},
answer_url = new[]
{
NEXMO_CALL_ANSWER_URL
}
});
Here's a detailed post on how to make a phone call with Nexmo Voice API and ASP.Net
If you want to use phone line you should use Computer-telephony boards, for example Dialogic: http://www.dialogic.com/products/ip_enabled/ip_boards.htm They should have API, so you will be able to use it from your application.
In addition to Asterisk, you might also consider Twilio, a web based telephony service that provides you a rest based api for making and receiving phone calls. See http://www.twilio.com/docs/howto/ for info.
You Can Use Third party API To Make a Call Using Asp.net Code.First You Need To Register. Here's a detailed post on
How To Make a Call Using Asp.net Code
protected void btnCall_click(object sender, EventArgs e)
{
// Call porcessing happens here.
// Use your account SID and authentication token instead of
// the placeholders shown here.
var accountSID = "C0d09f4042d1ff4acb55329cf8e5efb";
var authToken = "05b278c6f3538d3a35f13b25c73dff";
// Instantiate an instance of the Twilio client.
TwilioClient.Init(accountSID, authToken);
// Retrieve the account, used later to retrieve the
var account = AccountResource.Fetch(accountSID);
// this.varDisplay.Items.Clear();
// Retrieve the values entered by the user.
var To =new PhoneNumber(txtMobileNumber.Text);
//twlio=14155992671
var from = new PhoneNumber("+918098641075");
var myMessage = this.txtMessage.Text;
// Create a URL using the Twilio message and the user-entered
// text. You must replace spaces in the user's text with '%20'
// to make the text suitable for a URL.
var url = #"http://twimlets.com/message?Message%5B0%5D={myMessage.Replace()}";
var twimlUri = new Uri(url);
// Display the endpoint, API version, and the URL for the message.
this.varDisplay.Items.Add(#"Using Twilio endpoint { }");
this.varDisplay.Items.Add(#"Twilioclient API Version is {apiVersion}");
this.varDisplay.Items.Add(#"The URL is {url}");
// Place the call.
var Call=CallResource.Create(To,from,url:twimlUri);
// var call = CallResource.create(to, from, url: twimlUri);
this.varDisplay.Items.Add("Call status: " + Call.Status);
}

Categories