I am designing an app for iPhone and android in which I have to integrate facebook, twitter, yahoo, gmail, openId. I had integrated facebook and twitter, but how to go for yahoo, gmail and openId? How to login these through app and get the user information?
Please do show me a way to implement this. Any tutorial may help.
Thanks.
To integrate gmail may this url's help you
Google's documentation
Introduction about integrating gmail with iphone
Examples to integrate with iphone
Api's for integrating blogger,google analytics etc
For yahoo you can use this
String YAHOO_RESOURCE_URL = "http://social.yahooapis.com/v1/me/guid/profile?fomat=xml";
String CALLBACK_URL = "oauth://testApp";
String YAHOO_REQUEST_TOKEN_URL = "https://api.login.yahoo.com/oauth/v2/get_request_token";
String YAHOO_ACCESS_TOKEN_URL = "https://api.login.yahoo.com/oauth/v2/get_token";
String YAHOO_AUTHORIZE_URL = "https://api.login.yahoo.com/oauth/v2/request_auth";
// Oauth consumer and provider.
CommonsHttpOAuthConsumer consumer = new CommonsHttpOAuthConsumer(Constants.YAHOO_CONSUMER_KEY, Constants.YAHOO_CONSUMER_SERECT_KEY);
OAuthProvider provider = new CommonsHttpOAuthProvider(YAHOO_REQUEST_TOKEN_URL , YAHOO_ACCESS_TOKEN_URL, YAHOO_AUTHORIZE_URL);
provider.setOAuth10a(true);
// First retrive request token.
String authUrl = provider.retrieveRequestToken(consumer, CALLBACK_URL);
String yahooToken = consumer.getToken();
String yahooTokenSecret = consumer.getTokenSecret();
Open the authUrl in android web browser, this will launch login page, then after login will ask for permissions, accepting the permissions will return in your app using callback url.
Now,
In onResume
Uri uri = this.getIntent().getData();
if (uri != null && uri.toString().startsWith(CALLBACK_URL)) {
String oauthToken = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_TOKEN);
String oauthVerifier = uri.getQueryParameter(oauth.signpost.OAuth.OAUTH_VERIFIER);
consumer = new CommonsHttpOAuthConsumer(Constants.YAHOO_CONSUMER_KEY, Constants.YAHOO_CONSUMER_SERECT_KEY);
consumer.setTokenWithSecret(yahooToken, yahooTokenSecret);
provider = new CommonsHttpOAuthProvider(YAHOO_REQUEST_TOKEN_URL, YAHOO_ACCESS_TOKEN_URL, YAHOO_AUTHORIZE_URL);
provider.setOAuth10a(true);
// Now retrive access token
provider.retrieveAccessToken(consumer, oauthVerifier);
String token = consumer.getToken();
String tokenSecret = consumer.getTokenSecret();
consumer.setTokenWithSecret(token, tokenSecret);
// Get the GUID from this.
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet request = new HttpGet("http://social.yahooapis.com/v1/me/guid?format=json");
consumer.sign(request);
HttpResponse response = httpClient.execute(request);
Parse the response to get GUID.
// Now use the GUID to get profile info.
DefaultHttpClient httpClient = new DefaultHttpClient();
String strUrl = "http://social.yahooapis.com/v1/user/"+ strGUID +"/profile?format=json";
HttpGet request = new HttpGet(strUrl);
consumer.sign(request);
HttpResponse response = httpClient.execute(request);
Parse the response and njoy :)
Related
I've built a client (in .NET, but it could be in any framework) to consume the Payflow Gateway NVP API using the Transparent Redirect and Secure Token features. I am able to receive the token, send the credit card data, and receive an Approved response from PayPal. The problem is that PayPal is not redirecting properly back to my site. I passed a RETURNURL (http://localhost:49881/transaction/details?processor=PayflowGateway) parameter when requesting the Secure Token, but instead of returning me to that URL after the transaction, it navigates my browser to the following URL:
https://pilot-payflowlink.paypal.com/http%3A%2F%2Flocalhost%3A49881%2Ftransaction%2Fdetails%3Fprocessor%3DPayflowGateway?POSTFPSMSG=No%20Rules%20Triggered&RESPMSG=Approved&ACCT=1111&COUNTRY=US&PROCCVV2=M&VISACARDLEVEL=12&CVV2MATCH=Y&CARDTYPE=0&PNREF=A70A8EB8B6A1&AVSDATA=XXN&SECURETOKEN=9eGKZsSldEU6mIdSEV5DB4wWd&PREFPSMSG=No%20Rules%20Triggered&SHIPTOCOUNTRY=US&AMT=14.75&SECURETOKENID=1850a8f2-f180-4474-aa31-35d736fd7921&TRANSTIME=2016-03-24%2007:58:48&HOSTCODE=A&COUNTRYTOSHIP=US&RESULT=0&BILLTOCOUNTRY=US&AUTHCODE=872PNI&EXPDATE=1218
I have tried removing the "?processor=PayflowGateway" to fix the multiple question mark issue in the URL, but that doesn't seem to help. I've also tried tagging the RETURNURL[xx] with xx being the length of the URL value, but that seems to be the same as not passing a RETURNURL at all as it just shows a confirmation page on paypal.com instead of redirecting back to my site.
In PayPal Manager, I set the "Show confirmation page" setting to "On my website", Return URL to blank, and Return URL Method to GET. Are there any other settings or API request changes I need to make to get this to return properly to my test site?
This problem is caused because you're URL-Encoding the RETURNURL parameter passed when requesting the secure token from payflowpro gateway.
See the Do Not URL Encode Name-Value Parameter Data section on the Integration Guide.
Also, here you can get some C# code working you can use.
And some guidelines about PayPal HTTP here.
Do not use System.Net.Http.HttpClient nor System.Net.WebClient to make the HTTP POST to request the secure token. Instead use the low level System.Net.WebRequest to be able to write the POST data unencoded.
For example:
private string RequestSecureToken(double amount)
{
var secureTokenId = Guid.NewGuid().ToString();
var requestId = Guid.NewGuid().ToString();
var pairs = new Dictionary<string, string>()
{
{"PARTNER", "PayPal"},
{"VENDOR", "VENDOR NAME"},
{"USER", "USER NAME"},
{"PWD", "PASSWORD"},
{"TRXTYPE", "S"},
{"AMT", amount.ToString()},
{"CREATESECURETOKEN", "Y"},
{"SECURETOKENID", secureTokenId},
{"SILENTTRAN", "TRUE"},
{"RETURNURL", "http://mycompany.com/success"},
{"ERRORURL", "http://mycompany.com/error"}
};
string postData = string.Join("&", pairs.Select(p => string.Format("{0}[{2}]={1}", p.Key, p.Value, p.Value.Length)));
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://pilot-payflowpro.paypal.com");
request.Method = "POST";
request.ContentType = "text/namevalue";
request.Headers.Add("X-VPS-CLIENT-TIMEOUT", "45");
request.Headers.Add("X-VPS-REQUEST-ID", requestId);
request.ContentLength = postData.Length;
using (var writer = new StreamWriter(request.GetRequestStream()))
{
writer.Write(postData);
}
//Get the response
var response = request.GetResponse();
using (var reader = new StreamReader(response.GetResponseStream()))
{
return reader.ReadToEnd();
}
}
I would like to fetch a user's email using the C# Facebook SDK. How can I do so? I've tried the code below, but I just get an empty email. Is it because I somehow need to ask for more rights? If so, how do I do that?
Facebook.FacebookClient fbc = new Facebook.FacebookClient(user.MobileServiceAuthenticationToken);
dynamic clientCredentials = await fbc.GetTaskAsync("oauth/access_token",
new{client_id = facebookClientId,client_secret = facebookClientSecret,
grant_type = "client_credentials",redirect_uri = "https://xxx.azure-mobile.net/signin-facebook"});
fbc.AccessToken = clientCredentials.access_token;
fbc.AppId = facebookClientId;
fbc.AppSecret = facebookClientSecret;
string id = user.UserId.Replace("Facebook:", string.Empty);
dynamic result = await fbc.GetTaskAsync(id + "?fields=id,name,picture,last_name,first_name,gender");
Best regards
TJ78
You need to gather the email permission in the login Url's scope parameter, otherwise you will not be able to receive the email field.
I am using https://github.com/sanjeevdwivedi/facebook-csharp-sdk to integrate facebook in my wp8 app.
I want to know how to access the user email id using facebook-csharp-sdk below is the code I am using
FacebookSession session = FacebookSessionClient.LoginAsync("user_about_me,read_stream");
FacebookClient _fb = new FacebookClient(session.AccessToken);
dynamic parameters = new ExpandoObject();
parameters.access_token = session.AccessToken;
parameters.fields = "email,first_name,last_name";
dynamic result = await _fb.GetTaskAsync("me", parameters);
But I am getting only firstname , lastname and id of the logged in result field. Please suggest where am i missing?
You should ask for the email permission.
FacebookSession session = FacebookSessionClient.LoginAsync("user_about_me,read_stream,email");
The last item in the LoginAsync params I placed is email
See permissions for more info
In my application image has to post to Facebook,mail.Sorry i am new to windows phone.i don't have a idea.please help me.what i can do first.
If you want to share a status you can use your facebook account on your phone using Share link task (with this method you can only post on your wall) http://msdn.microsoft.com/en-us/library/hh394027%28v=vs.92%29.aspx
To post (pictures, messages or others) on every wall you have access you need some things :
First you need to create a facebook application using this link :
Facebook developers
After that you need to identify yourself using a WebBrowser control with the link related to your application. The application requests authorization to perform certain actions such as posting. You need to detail the authorizations like this :
Dictionary<string, string> uriParams = new Dictionary<string, string>() {
{"client_id", "your app id"},
{"response_type", "token"},
{"scope", "user_about_me, offline_access, publish_stream"}, //The rights
{"redirect_uri", "http://www.facebook.com/connect/login_success.html"},
{"display", "touch"}
};
The Dictionary also contains the redirection uri to define if the operation was successful.
Finally you are authentified and receive an access token. Now you can use a WebRequest POST to post a message using this token :
WebRequest request = HttpWebRequest.Create("https://graph.facebook.com/" + the id of your wall + "/feed");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.BeginGetRequestStream((reqResult) =>
{
using (Stream strm = request.EndGetRequestStream(reqResult))
using (StreamWriter writer = new StreamWriter(strm))
{
writer.Write(client.AccessToken);
writer.Write("&message=" + HttpUtility.UrlEncode(status));
}
request.BeginGetResponse((result) =>
{
try
{
var response = request.EndGetResponse(result);
using (var rstrm = response.GetResponseStream())
{
var serializer = new DataContractJsonSerializer(typeof(FacebookPostResponse));
var postResponse = serializer.ReadObject(rstrm) as FacebookPostResponse;
callback(true, null);
}
}
catch (Exception ex)
{
callback(false, ex);
}
}, null);
}, null);
Here is how to post a message on a facebook page,
You should give the Facebook C# SDK a try
Facebook C# SDK
I have built this in once in an app of mine. They have plenty examples available which should be useful.
How to create a facebook event by using facebook api in asp.net.
Thanks.
public string CreateEvent(string accessToken)
{
FacebookClient facebookClient = new FacebookClient(accessToken);
Dictionary<string, object> createEventParameters = new Dictionary<string, object>();
createEventParameters.Add("name", "My birthday party )");
createEventParameters.Add("start_time", DateTime.Now.AddDays(2).ToUniversalTime().ToString());
createEventParameters.Add("end_time", DateTime.Now.AddDays(2).AddHours(4).ToUniversalTime().ToString());
createEventParameters.Add("owner", "Balaji Birajdar");
createEventParameters.Add("description", " ( a long description can be used here..)");
//Add the "venue" details
JsonObject venueParameters = new JsonObject();
venueParameters.Add("street", "dggdfgg");
venueParameters.Add("city", "gdfgf");
venueParameters.Add("state", "gfgdfgfg");
venueParameters.Add("zip", "gfdgdfg");
venueParameters.Add("country", "gfdgfg");
venueParameters.Add("latitude", "100.0");
venueParameters.Add("longitude", "100.0");
createEventParameters.Add("venue", venueParameters);
createEventParameters.Add("privacy", "OPEN");
createEventParameters.Add("location", "fhdhdfghgh");
//Add the event logo image
FacebookMediaObject logo = new FacebookMediaObject()
{
ContentType = "image/jpeg",
FileName = #"C:\logo.jpg"
};
logo.SetValue(File.ReadAllBytes(logo.FileName));
createEventParameters["#file.jpg"] = logo;
JsonObject resul = facebookClient.Post("/me/events", createEventParameters) as JsonObject;
return resul["id"].ToString();
}
I am using facebook graph apis with FacebookSdk from codeplex.
I am not able to post the venue with this code due to the open bug in facebook API. Other things work fine. I suggest you implement this venue parameters as well so that the functionality will work as soon as facebook resolves this issue.
Mark this as answer if it works for you.It will also help other people to save time on searching.
You might try this http://developers.facebook.com/docs/api