I try to get the last 20 statuses of the Usertimeline. So I search in the internet and get
the follow code:
TwitterUser twitterUser = TwitterUser.Show("Username").ResponseObject;
if (twitterUser != null)
{
UserTimelineOptions userTimelineOptions = new UserTimelineOptions();
userTimelineOptions.UserId = twitterUser.Id;
return TwitterTimeline.UserTimeline(userTimelineOptions).ResponseObject;
}
return null;
When I test it, I get the follow exception:
Unexpected token when deserializing object: StartObject. Line 1, position 1795.
I have no idea what's wrong so I hope you can help me!
Since Twitterizer is discontinued, I assumed that you moved to TweetSharp:
TwitterService service = new TwitterService("consumerKey", "consumerSecret");
service.AuthenticateWith("accessToken", "accessTokenSecret");
var options = new ListTweetsOnHomeTimelineOptions();
options.ExcludeReplies = true;
var tweets = service.ListTweetsOnHomeTimeline(options);
For Twitterizer:
UserTimelineOptions options = new UserTimelineOptions();
options.ScreenName = "Username";
var tweets = TwitterTimeline.UserTimeline(options).ResponseObject;
Twitterizer uses the 1.0 API and TweetSharp has the required oAuth for the 1.1 twitter API:
https://dev.twitter.com/blog/changes-coming-to-twitter-api
Try this
var twitterService = new TwitterService("consumerKey", "consumerSecret");
twitterService.AuthenticateWith("token", "tokenSecret");
var tweets = twitterService.ListTweetsOnHomeTimeline();
Related
im very new with Facebook apps and read several threads for creating them, but I have some problems with it.
First of all what I want to do: I want to create a web application that is able to post pictures, text and links on a facebook page that is managed by me.
I used the Facebook C# SDK: here!
What I have:
string facebookPageId = "<my page id>";
string app_id = "<my app id>";
string app_secret = "<my app secret>";
string scope = "publish_stream,manage_pages";
var fb = new FacebookClient();
dynamic res = fb.Get("oauth/access_token", new
{
client_id = app_id,
client_secret = app_secret,
grant_type = "client_credentials"
});
var access_token = res.access_token;
dynamic messagePost = new ExpandoObject();
messagePost.access_token = access_token;
messagePost.link = "http://www.test.at";
messagePost.name = "Testbot";
messagePost.caption = "{*actor*} " + "hello this is a test";
messagePost.description = "[SOME_DESCRIPTION]";
FacebookClient app = new FacebookClient(access_token);
app.AppId = app_id;
app.AppSecret = app_secret;
try
{
var result = app.Post("/hrechttest" + "/feed", messagePost);
}
catch (Exception e)
{
}
Well the code runs without any exceptions but in the output window I get the following:
Exception thrown: 'Facebook.FacebookOAuthException' in Facebook.dll
The next problem is:
As I understood it you must link your facebook app with your facebook page, but when I want to do that I cant select the page:
So what I did wrong or missed?
publish_stream is deprecated since many years, publish_pages is the correct permission to post to a Page (as Page).
API reference: https://developers.facebook.com/docs/graph-api/reference/page/feed#publish
Make sure you are using a Page Token, not a User Token:
https://developers.facebook.com/docs/facebook-login/access-tokens
http://www.devils-heaven.com/facebook-access-tokens/
How to create Page Apps is explained in the docs too: https://developers.facebook.com/docs/pages/tabs
I am trying to get TweetSharp to search with twitter. It always returns null. There is no error or other information. I setup my consumerkey, consumer secret, access token, and token secret
Here is my code:
TwitterService service = new TwitterService(consumerKey, consumerSecret);
service.AuthenticateWith(accessToken, tokenSecret);
SearchOptions options = new SearchOptions { Q = "#VeternsDay", Count = 100, Resulttype = TwitterSearchResultType.Recent };
TwitterSearchResult searchedTweets = service.Search(options);
return searchedTweets;
I know this question is old, but I was playing around C# and Tweetsharp and saw your question and tried to solve it :)
I tried to recreate your example and I got it working! You needed to loop over the searchedTweets.Statuses and get their contents. In this example I got the 100 popular tweets in the #Bahrain hashtag and got those tweets username authors.
var service = new TwitterService(consumerKey, consumerSecret);
service.AuthenticateWith(accessToken, accessTokenSecret);
SearchOptions options = new SearchOptions { Q = "#Bahrain", Count = 100, Resulttype = TwitterSearchResultType.Popular};
TwitterSearchResult searchedTweets = service.Search(options);
foreach(var tweet in searchedTweets.Statuses)
{
MessageBox.Show( tweet.Author.ScreenName);
}
I'm having some difficulties getting the OAuth2 working for the Basecamp API with DotNetOpenAuth, here's what I have so far, this is a ASP.NET MVC 4 web app.
public ActionResult Basecamp()
{
var server = new DotNetOpenAuth.OAuth2.AuthorizationServerDescription();
server.AuthorizationEndpoint = new Uri("https://launchpad.37signals.com/authorization/new");
server.TokenEndpoint = new Uri("https://launchpad.37signals.com/authorization/token");
var client = new DotNetOpenAuth.OAuth2.WebServerClient(
server, "my-basecamp-id", "my-basecamp-secret");
client.RequestUserAuthorization(returnTo: new Uri("http://localhost:55321/settings/basecampauth"));
Response.End();
return null;
}
[HttpPost]
public ActionResult BasecampAuth()
{
var server = new DotNetOpenAuth.OAuth2.AuthorizationServerDescription();
server.AuthorizationEndpoint = new Uri("https://launchpad.37signals.com/authorization/new");
server.TokenEndpoint = new Uri("https://launchpad.37signals.com/authorization/token");
var client = new DotNetOpenAuth.OAuth2.WebServerClient(
server, "my-basecamp-id", "my-basecamp-secret");
var state = client.ProcessUserAuthorization(Request);
Response.Write(state.AccessToken);
Response.End();
return null;
}
The is the error I get from Basecamp:
---
:error: "Unsupported type: nil. We support user_agent and web_server."
I've tried to search and look around, and could not found much interesting. Any help / pointer would be appreciated.
Thanks
Change this:
server.AuthorizationEndpoint = new Uri("https://launchpad.37signals.com/authorization/new");
to this:
server.AuthorizationEndpoint = new Uri("https://launchpad.37signals.com/authorization/new?type=web_server");
Note: i added type=web_server to the end of the uri.
Take from these official docs.
I use the PayPal Express Checkout SOAP service. For example here's a trimmed down version of the code to redirect the user to PayPal Sandbox when checking out:
var client = new PayPalAPIAAInterfaceClient();
var credentials = new CustomSecurityHeaderType() {
Credentials = new UserIdPasswordType() { ... }
};
var paymentDetails = new PaymentDetailsType() {
OrderTotal = new BasicAmountType() {
Value = string.Format("{0:0.00}", 100m)
}
};
var request = new SetExpressCheckoutReq() {
SetExpressCheckoutRequest = new SetExpressCheckoutRequestType() {
SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType() {
PaymentDetails = new PaymentDetailsType[] { paymentDetails },
CancelURL = "http://www.mysite.com" + Url.Action("Cancelled", "PayPalCheckout"),
ReturnURL = "http://www.mysite.com" + Url.Action("Index", "PayPalCheckout")
},
Version = "60.0"
}
};
var response = client.SetExpressCheckout(ref credentials, request);
return Redirect(string.Format("{0}?cmd=_express-checkout&token={1}", "https://www.sandbox.paypal.com/cgi-bin/webscr", response.Token));
I then handle the data when the user is returned to the ReturnUrl. This was taken from some code I found on another website.
I now need to add a refund facility to my site. I was wondering if anyone else has done this? I've tried searching online but can't seem to find anything that helps. I also tried doing it myself but the API isn't very intuitive.
I'd appreciate the help. Thanks
It would just need to be a RefundTransaction API call that you would need to execute. Are you trying to have your return page issue a refund based on a condition, or are you trying to create a GUI type of interface to allow someone to issue a refund for a transaction? Have you looked at the code samples for this within the SDK's that PayPal offers? You should be able to use this code.
I tried this:
oAuthClient = new FacebookOAuthClient(FacebookApplication.Current);
oAuthClient.RedirectUri = callBack;
var parameters = new Dictionary<string, object>();
parameters.Add("permissions", "offline_access,publish_stream");
var loginUri = oAuthClient.GetLoginUrl(parameters);
this brings me the access token , i save it in Database
now i try to post to facebook doing this :
var postparameters = new Dictionary<string, object>();
postparameters["message"] = tweet;
postparameters["name"] = "This is a name";
_fbClient = new FacebookClient(accessToken);
var result = _fbClient.Post("/me/feed", postparameters);
problem is this tells me that im not authorized to post. so in order to make it work i have to visit this url :
http://www.facebook.com/authorize.php?api_key=[key]&v=1.0&ext_perm=publish_stream
this also have a problem cause this link doesnt redirect back !
so the question is how i do get the access token from the first place with the publish_stream permission?
change
parameters.Add("permissions", "offline_access,publish_stream");
to
parameters.Add("scope", "offline_access,publish_stream");