3-legged-oauth and Google ContactsClient problem - api

legged-oauth to import a users' Google contacts in my app.
I did not find the ContactsClient library but i was using only the ContacsService and i was fetching the ContactsFeed but that resulted to not having a lot of data.
After the user allows my apps i store the auth_token key and secret so i can run a cron task to fetch contacts' updates
I am using this code atm:
google = gdata.contacts.service.ContactsService(source=GOOGLE_OAUTH_SETTINGS['APP_NAME'])
google.SetOAuthInputParameters(GOOGLE_OAUTH_SETTINGS['SIG_METHOD'],
GOOGLE_OAUTH_SETTINGS['CONSUMER_KEY'],
consumer_secret=GOOGLE_OAUTH_SETTINGS['CONSUMER_SECRET'])
access_token = gdata.auth.OAuthToken(user_oauth_token, user_oauth_secret)
access_token.oauth_input_params = google.GetOAuthInputParameters()
google.SetOAuthToken(access_token)
feed = google.GetContactsFeed()
When i try to use the contacts client
contacts_client = gdata.contacts.client.ContactsClient(
source=GOOGLE_OAUTH_SETTINGS['APP_NAME'])
feed2 = contacts_client.GetContacts(auth_token = access_token)
I get the following error (please note that the access_token is the same as above and I user 3-legged-oauth HMAC)
Actual results:
File "/Library/Python/2.5/site-packages/atom/client.py", line 108, in request
auth_token.modify_request(http_request)

Related

updateTenants not working after token refreshed

I'm in the process of updating our app from from oauth 1 to 2. Entire flow works well - I can migrate and save the tokens and access the APIs. However, there is a problem once the original token expires and it gets refreshed. After refreshing, the call to updateTenants does not return any active connections.
My pseudocode is below:
const tokenSet = await getTokenSet(); // Returns saved token set from DB. Assume token is expired!!
const client = new XeroClient(...);
client.setTokenSet(tokenSet);
const newToken = await client.refreshToken();
await saveTokenSet(newToken); // Save to DB
const token = client.readTokenSet();
console.log(token); // Does return my NEW active token set
const tenants = await client.updateTenants(false);
console.log(tenants.body); // This returns an array of length 0
Not clear why the results from updateTenants is empty. I was able to verify this by calling the GET https://api.xero.com/connections endpoint manually with one of the refreshed tokens and also see an empty array in the body.
Any ideas?
I played around with our xero-node-oauth2-app to see if I could recreate this. Here's what I found:
If I connected to my Xero org to obtain valid tokens and then disconnected via the Xero connected apps dashboard and then refreshed my tokens triggering updateTenants the connections endpoint returns an empty array and status code 200. In other words, it's a successful call but Xero doesn't see that the user has authorized your integration to interact with any of their orgs/tenants.
Are you able to verify if your integration is still listed in the connected apps list under settings?
https://community.xero.com/developer/discussion/127403806

Download / backup all soundcloud user data

I tried searching for a tool that would download all data related to a soundcloud user (uploaded tracks, likes/collection, reposts, playlists, comments, groups etc), backing it up locally, but haven't had luck so far. The user data format is not crucially important, and could be something like XML or JSON. I guess it wouldn't be hard to create it using their API, but I thought it's strange there's no tool like that already, so I wanted to ask here first.
Not a complete answer, but I'll just gather here a few bits of information that might be useful to somebody eventually. Based on this article https://helgesverre.com/blog/fetch-info-from-soundcloud-api/
First you need to register an app here, where you'll get your client id
http://soundcloud.com/you/apps/new
$clientid = "*******"; // Your API Client ID
$userid = "****"; // ID of the user you are fetching the information for
$username = "*****";
// build our API URL
$url = "http://api.soundcloud.com/resolve.json? url=http://soundcloud.com/{$username}&client_id={$clientid}";
$user_json = file_get_contents($url);
$tracks_url = "http://api.soundcloud.com/users/{$userid}/tracks.json?client_id={$clientid}";
$tracks_json = file_get_contents($tracks_url);
$playlists_url = "http://api.soundcloud.com/users/{$userid}/playlists.json?client_id={$clientid}";
$playlists_json = file_get_contents($playlists_url);
$followings_url = "http://api.soundcloud.com/users/{$userid}/followings.json?client_id={$clientid}&page_size=200"; // 200 is max
$followings_json = file_get_contents($followings_url);
$followers_url = "http://api.soundcloud.com/users/{$userid}/followers.json?client_id={$clientid}&page_size=200"; // 200 is max
$followers_json = file_get_contents($followers_url);
$reposts_url = "http://api-v2.soundcloud.com/profile/soundcloud:users:{$userid}?client_id={$clientid}&limit=1000&offset=0"; // 1000 works
$reposts_json = file_get_contents($reposts_url);

twitter stream API track all tweet posted by user who registered in twitter application

I am creating the application which need to track all tweets from user who registered to my application, i tried to track those with streaming API , there are public API, user API , and site API,
in those API it just have an option to follow the user ID by add the comma separated user ID
https://dev.twitter.com/streaming/overview/request-parameters#follow
but i think it is not flexible, if there are a new user registered , i need to rebuild the HTTP request , and also if there are so many users try to listen this stream and query will be so long,
it will be
https://stream.twitter.com/1.1/statuses/filter.json?follow=[user1],[user2],[user3]........[userN],
i afraid the query wont fit, i just need a parameter to filter all user who registered in my application such as, for example.
https://stream.twitter.com/1.1/statuses/filter.json?application=[applicationID]
but i think twitter dev does not provide it
so, is there any way to filter stream by application ID?
I didn't see anything like tracking by application id. If your query become too complex (too many follows/keywords), public streaming api will reject it,
and you can't open more than 2 connections with user stream. So, last solution is using Site Stream, -> you can open as many user connections as you have users registered to your app.
BUT the docs says :
"Site Streams is currently in a closed beta. Applications are no
longer being accepted."
Contact twitter to be sure
Arstechnica has a very interesting article about it. Take a look at this code and the link in the end of this post
If you are using python pycurl will do the job. Its provides a way to execute a function for every little piece of data received.
import pycurl, json
STREAM_URL = "http://chirpstream.twitter.com/2b/user.json"
USER = "YOUR_USERNAME"
PASS = "XXXXXXXXX"
userlist = ['user1',...,'userN']
def on_receive(self, data):
self.buffer += data
if data.endswith("rn") and self.buffer.strip():
content = json.loads(self.buffer)
self.buffer = ""
if "text" in content and content['user'] in userlist:
#do stuff
conn = pycurl.Curl()
conn.setopt(pycurl.USERPWD, "%s:%s" % (USER, PASS))
conn.setopt(pycurl.URL, STREAM_URL)
conn.setopt(pycurl.WRITEFUNCTION, on_receive)
conn.perform()
You can find more information here Real time twitter stream api

Invalid twitter oauth token for Abraham's Oauth class

Here's my current operations:
1./ User accepts app and the app callback stores the oauth_token and oauth_token_secret into the database (as access_token and access_token_secret).
2./ We use a cli script to handle autoposting to twitter. We load the twitter oauth object as follows:
public function post()
{
$consumerKey = $this->getConsumerKey();
$consumerSecret = $this->getConsumerSecret();
$accessToken = $this->getAccessToken();
$accessSecret = $this->getAccessSecret();
$twitteroauth = new TwitterOAuth($consumerKey,$consumerSecret,$accessToken,$accessSecret);
$message = $this->getPostMessage();
$result = $twitteroauth->post('statuses/update', array('status' =>$message));
$this->log($result);
}
Now this assumes we are using the API consumer key and secret assigned to the app and the user's stored access tokens.
The result we are getting is:
Invalid or expired token
I don't quite understand why we are receiving this. We are using the access token and access token secret provided to us by twitter.
I did notice that there is a GET parameter oauth_verifier. This isn't something we need to be using somewhere?
In any case, I'm not quite sure whats wrong here.
Do I need to log in or something before doing posting?
your code is correct.
The problem is that the library's Util.urlParameterParse() method is broken.

How to get useID/Email of logged in user in Google Contacts API after OauTh Token

I developed a program which works well and I can import data from gmail but. I want to keep track how is the user given permission to manage contacts. But after a hard search I did not get any Idea about the loged in user. My code is as follows.
============================================
var parameters = new OAuth2Parameters
{
ClientId = ConfigurationManager.AppSettings["ClientID"].ToString(),
ClientSecret = ConfigurationManager.AppSettings["ClientSecret"].ToString(),
RedirectUri = ConfigurationManager.AppSettings["RedirectURL"].ToString(),
Scope ="https://www.googleapis.com/auth/userinfo.profile"
};
parameters.AccessCode = Request.QueryString["Code"].ToString();
OAuthUtil.GetAccessToken(parameters);
Session["Token"] = parameters.AccessToken;
==================================
But I dont how to get email of logged in user. Please let me that
Thanks in advance
Request an additionall scope of https://www.googleapis.com/auth/userinfo.email and then you can access the user info as well. There is also a userinfo.profile witch contains other info on the user like name, profile picture, language and so on.
Your code looks like C# but I only have a Python example of using multiple scopes and sharing tokens.
Code: https://code.google.com/p/google-api-oauth-demo/
Article: http://www.hackviking.com/2013/10/python-get-user-info-after-oauth/