I am connecting to login facebook page through an url. I receive the access token in my application and i can prints all my contacts from the list. I have a problem: there are times when i do receive the access token and if i logout from facebook and rebuild my application the second time , i don't have any access token. WHY? If i wait i guess 10-15 minutes and try again it works. How to resolve this? THX
I am using the auth url. THe following link was my example link:
http://geekdeck.com/vb-net-facebook-get-access-token-for-desktop-application/
EDIT:
I have the following code:
browserFacebook.Navigate(#"https://graph.facebook.com/oauth/authorize?client_id="+ FacebookApplicationID + "&redirect_uri=http://www.facebook.com/connect/login_success.html&type=user_agent&display=popup");
string someString = browserFacebook.Url.ToString();
This returns something like the following:
"http://www.facebook.com/connect/login_success.html#access_token=ACCESS TOKEN.expires_in=0"
I can then easily use this access token with the Graph API to access an users facebook details as in the following code:
Facebook.FacebookGraphAPI g = new FacebookGraphAPI("ACCESS_TOKEN");
var fbUser = g.GetObject("me", null);
PROBLEM:
When I rebuild the application, the link that i receive is OpenDNS (or navigation to the webpage was canceled) and I have to access token. Why? How can I resolve this error? After a a while 1-2 hours I receive again the token.
"https://graph.facebook.com/oauth/authorize?client_id=" +
FacebookApplicationID +
"&redirect_uri=http://www.facebook.com/connect/login_success.html&type=user_agent&display=popup");
Related
I hope this makes sense. I am using the Zoho C# SDK examples to write records to the CRM Leads. While calling recordOperations.CreateRecords(); it fails after trying to GetToken from the Token Store.
Here is the token I am saving
Token token = new OAuthToken(
"xxxx.clientid.goes.here.xxxxx",
"xxxx.clientsecret.goes.here.xxxx",
"REFRESH/GRANT token",
TokenType.GRANT,
string.Empty);
TokenStore tokenStore = new CustomTokenStore();
tokenStore.SaveToken(user, token);
And I am sending this token into the SDKInitilizer.Initialize. No errors at this point. Next I try and create a lead. When it gets inside of recordOperations.CreateRecords(); it tries GetToken and I've hard coded it to return exactly what was in the token object above. CreateRecords throws an error for "invalid_code". Here is what is in the log file
21-09-07 16:49:34 [INFO]: Initialization successful for Email Id : myemail#email.com in Environment : https://www.zohoapis.com.
21-09-07 16:49:47 [INFO]: Access Token has expired. Hence refreshing.
21-09-07 16:49:50 [ERROR]: Exception in authenticating current request : {"Code":"INVALID CLIENT ERROR","Message":"invalid_code","Cause":null,"Details":null,"StackTrace":" at Com.Zoho.API.Authenticator.OAuthToken.ParseResponse(String response)\r\n at Com.Zoho.API.Authenticator.OAuthToken.RefreshAccessToken(UserSignature user, TokenStore store)\r\n at Com.Zoho.API.Authenticator.OAuthToken.Authenticate(APIHTTPConnector urlConnection)\r\n at Com.Zoho.Crm.API.Util.CommonAPIHandler.APICall[T](Type className, String encodeType)","Data":{},"InnerException":null,"HelpLink":null,"Source":"ZCRMSDK","HResult":-2146233088}
It appears to be failing when it tries to refresh the token so I assume I am not sending in the right info in the token object?
*** Edit for #sucasa ***
This is what I am sending into the Initialize method.
What I have figured out since my first post is, I'm not getting the initial token from Initialize and its not calling the custom TokenStore.SaveToken() I created and it should, right? If I save it, all I have is what is above, not an actual token. So I think when I go to create the lead, I don't actually have the initial token to refresh. I hope that's clearer.
Access Tokens expire and must be refreshed using a refresh token. The error message indicates this. Can you log the value of token and report back here?
Basically what I'm trying to do is to get recent tweets from a user and do stuff with them. I'm using Tweetinvi with PIN-based authentication, as described on the website, like this:
// Create a new set of credentials for the application
var appCredentials = new TwitterCredentials("CONSUMER_KEY", "CONSUMER_SECRET");
// Go to the URL so that Twitter authenticates the user and gives him a PIN code
var url = CredentialsCreator.GetAuthorizationURL(appCredentials);
// This line is an example, on how to make the user go on the URL
Process.Start(url);
// Ask the user to enter the pin code given by Twitter
var pinCode = Console.ReadLine();
// With this pin code it is now possible to get the credentials back from Twitter
var userCredentials = CredentialsCreator.GetCredentialsFromVerifierCode(pinCode, appCredentials);
// Use the user credentials in your application
Auth.SetCredentials(userCredentials);
Now the problem is that I have to sign in and connect to Twitter every time I launch my application via browser, which is mildly annoying. I've tried to save my authentication details in a text file (Consumer Key, Consumer Secret, Access Token, Access Token Secret), and then just insert the info into appCredentials and userCredentials, but with no results, as I keep getting TwitterNullCredentialsException. So how do I save my credentials so that I don't have to reconnect on every launch?
I am the main developer of Tweetinvi.
If you store the 4 credentials information you can then reuse them with 2 different solutions :
Auth.SetUserCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
// OR
var creds = new TwitterCredentials("CONSUMER_KEY", "CONSUMER_SECRET", "ACCESS_TOKEN", "ACCESS_TOKEN_SECRET");
Auth.SetCredentials(creds);
The documentation might help you set up your application : https://github.com/linvi/tweetinvi/wiki/Introduction
I have the following error when using DropNet library to make connection to DropBox.
Trying to implement it for my CMS and also for my knowledge :)
trying the current documentation of DropNet.
Source:https://github.com/DropNet/DropNet
Current code:
var _client = new DropNetClient(Core.DropBoxAPI, Core.DropBoxKeySecret);
UserLogin login = _client.GetToken();
_client.UserLogin = login;
String Url = _client.BuildAuthorizeUrl();
Produces:
Received Response [Unauthorized] : Expected to see [OK]. The HTTP
response was [{"error": "Unauthorized"}].
Exception: DropNet.Exceptions.DropboxRestException: Received Response
[Unauthorized] : Expected to see [OK]. The HTTP response was
[{"error": "Unauthorized"}].
I want to let the user connect to the Url returned by _client.BuildAuthorizeUrl(); but it even won't let me get to url
and i also have a Key and Secret generated from DropBox.com
if i try to set the method _client.BuildAuthorizeUrl(); as first statement it gives also an error on the DropBox page itselfs.
I tried to find an another post on Stackoverflow but i didn't find any solution so fare.
Its still using the basics of the documentation and it goes wrong.
If you have any ideas that would be nice.
Thanks for the advices.
I was filling the secret the same as the APP key.
I'm making a small widget in c# to get the posts from a public facebook page/profile.
I believe you have to get a access token each time you make a request to the api?
I'm confused as to which access token I need and what url request string to use.
This is what I'm using currently but it brings back an unexpected looking key.
access_token=112121212121212|NxG_8djeufhfywhduEjaeU4J-lh4
(I've typed in random characters as an example of the structure).
string response = "https://graph.facebook.com/oauth/access_token?client_id=" + facebook_AppID + "&client_secret=" + facebook_AppSecret + "&grant_type=client_credentials";
string accesstoken = RequestResponse(response);
Then when I use that code to get the posts from a wall, using:
string urlGetFeed = "https://graph.facebook.com/thepagename?fields=access_token=" + accesstoken2 + ",posts.fields(message,picture)";
I get a ERROR : The remote server returned an error: (400) Bad Request. Error.
For the feed of a Facebook Page, you only need an App Access Token, which is easy to get:
APP-ID|APP-SECRET
For example:
string urlGetFeed = "https://graph.facebook.com/thepagename/feed?access_token=" + [app-id] + "|" + [app-secret];
Also, the Access Token is not a value of "fields", it´s a separate parameter.
The URL you should use is this:
https://graph.facebook.com/[THE_FACEBOOK_ID]/[WHAT_YOU_WANT]?access_token=[YOUR_ACCESS_TOKEN]&limit=[THE_LIMIT]
The first part access the Facebook graph.
The second part is the Facebook Id that you want.
The third part is the thing that you want from the Facebook Id that you entered (posts, feed, activities, etc). Here you must be sure that the Access Token has the permissions for what you want to get.
The fourth part is the Access Token that you get and the limit (if you don't set the limit the default limit from Facebook will be used).
Beware of the access token that you-re getting with the first line of code that you posted. That line will give you a short live access token. You should interchange the short live access token here:
https://graph.facebook.com/oauth/access_token?client_id=[YUOR_CLIENT_ID]&client_secret=[YOURCLIENT_SECRET]&grant_type=fb_exchange_token&fb_exchange_token=[THE_SHORT_LIVE_ACCESS_TOKEN]
EDIT:
What you should do is to include the FB Connect script:
<script type='text/javascript' src='http://connect.facebook.net/en_US/all.js#xfbml=1'</script>
and then use this function to take the user to the FB login (if it's not logged in) and then to the authorize page:
function createAccessToken()
{
FB.init({appId: '[YOUR APP ID]', status: true, cookie: true});
FB.login(function(response)
{
if (response.status == 'connected')
{
if (response.authResponse.accessToken)
{
var token = response.authResponse.accessToken;
}
else
{
alert('You must grant the permissions for this plugin or will not work.');
}
}
else
{
alert('You must be logged in to Facebook to grant permissions.');
}
}, { scope: 'read_stream' }); }
The token variable inside that function will contain the short lived access token to exchange for the long lived one here:
https://graph.facebook.com/oauth/access_token?client_id=[YOUR_CLIENT_ID]&client_secret=[YOURCLIENT_SECRET]&grant_type=fb_exchange_token&fb_exchange_token=[token]
Once you get that token go here to get what you want:
https://graph.facebook.com/[THE_FACEBOOK_ID]/[WHAT_YOU_WANT]?access_token=[YOUR_ACCESS_TOKEN]&limit=[THE_LIMIT]
I have been using google+ APIs for C# in my desktop application.I have to access the friends list of the google+ user.
I have been obtaining access token by extracting it from browser title.
It works fine for the following permissions(all grouped and asked at same time) and returns the authentication code in browser title(success=authcode).
"https://www.googleapis.com/auth/plus.me
"https://www.googleapis.com/auth/youtube",
"https://www.googleapis.com/auth/youtube.upload"
But when i changed the permission to obtain the friends list,
"https://www.googleapis.com/auth/plus.login
it's not returning the desired auth code ,it just returns success authuser=0&promt...
By the way I can't listen on local web server.
How to obtain the access token by using the above permission?
I just checked this and the success string in the window title is in fact different when you are using the plus.login scope. The code that is returned in the string is still valid though. The following code shows one way you could extract the authorization code from the window title string:
string pollActiveWindowForAuthCode(int sleepTime){
string activeTitle = GetActiveWindowTitle();
while (!activeTitle.StartsWith("Success"))
{
activeTitle = GetActiveWindowTitle();
Thread.Sleep(sleepTime);
}
// strip to start of auth code
string trimToAuthCode = activeTitle.Substring(activeTitle.LastIndexOf("=") + 1);
// trim the " - Google Chrome" text
return trimToAuthCode.Substring(0, trimToAuthCode.IndexOf(' '));
}
I have uploaded a more comprehensive demo to my GitHub:
csharp-gplus-wpf