Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 17th, 2012  |  syntax: None  |  size: 2.12 KB  |  hits: 10  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. //
  2. // blog.clearlyinnovative.com
  3. // Aaron K. Saunders
  4. // Clearly Innovative Inc
  5. //
  6. // @see https://github.com/aaronksaunders/Appcelerator-Cocoafish-Native-Module
  7. //
  8. var cocoafishMgr = require('com.ci.cocoafish');
  9. Ti.API.info("module is => " + cocoafishMgr);
  10.  
  11.  
  12. var cocoaFish = cocoafishMgr.create({
  13.         "consumer_key" : "your_consumer_key",
  14.         "secret_key" : "your_secret_key",
  15.         "facebookAppId" : "your_facebookAppId"
  16. });
  17. Ti.API.info("proxy is => " + cocoaFish);
  18.  
  19. function initWithTwitter() {
  20.         var twitterFactory = require('twitter');
  21.         var tt = new twitterFactory.twitter({
  22.                 service : 'twitter',
  23.                 consumer_key : "your_twitter_consumer_key",
  24.                 consumer_secret : "your_twitter_consumer_secret"
  25.         });
  26.  
  27.         //
  28.         // since we were successful, we can get the parameters needed to
  29.         // make the cocoafish api call to login/create external account.
  30.         //
  31.         // these configuration values are available from a customized
  32.         // version of the birdhouse.js twitter module
  33.         //
  34.         var authorizationSuccess = function() {
  35.                 var config, param_data;
  36.                 config = tt.getConfig();
  37.                 Ti.API.info("access_token is => " + config.access_token);
  38.                 Ti.API.info("user_id is => " + config.user_id);
  39.                 Ti.API.info("screen_name is => " + config.screen_name);
  40.  
  41.                 //
  42.                 // pass the params in following the cocoafish documentation
  43.                 var data = {
  44.                         type : "twitter",
  45.                         token : config.access_token,
  46.                         id : config.user_id
  47.                 };
  48.  
  49.                 //
  50.                 // make the API call and you are done.
  51.                 //
  52.                 // if the account exists already, then the user will be
  53.                 // logged in
  54.                 cocoaFish.apiCall({
  55.                         "baseUrl" : "users/external_account_login.json",
  56.                         "httpMethod" : "POST",
  57.                         "params" : data,
  58.                         success : function(d) {
  59.                                 Ti.API.info("responseText is => " + d.responseText);
  60.                                 Ti.API.info("metaDataText is => " + d.metaDataText);
  61.                                 var user = (JSON.parse(d.responseText)).response.users[0];
  62.                                 Ti.API.info("user is => " + user);
  63.                         },
  64.                         error : function(d) {
  65.                                 Ti.API.error("error is => " + d.errorText);
  66.                         }
  67.                 })
  68.         }
  69.         //
  70.         // call to authorize with twitter account information. On success an account
  71.         // will be created for you. In the future you can login with the same twitter
  72.         // credentials
  73.         tt.authorize(authorizationSuccess);
  74. }