Class 'Thujohn\Twitter\TwitterFacade' not found in Laravel 5 - twitter

I'm trying to send a tweet from my Laravel 5 app using thujohn/twitter, but I get this error:
Class 'Thujohn\Twitter\TwitterFacade' not found
Here's my code
return Twitter::postTweet(array('status' => 'Tweet sent using Laravel and the Twitter API!', 'format' => 'json'));
Where is the error?

This alias no longer works in Laravel 5:
'Twitter' => 'Thujohn\Twitter\TwitterFacade',
You must use
'Twitter' => 'Thujohn\Twitter\Facades\Twitter',
Instead in config/app.php

Related

Omnicontact redirect_uri_mismatch with gmail account

I'm using Omnicontact gem but I have some problem making it works with gmail: I always get "redirect_uri_mismatch" error!
Here's the code of 'config/inizializers/omnicontacts.rb'
3 require "omnicontacts"
4
5 Rails.application.middleware.use OmniContacts::Builder do
6 importer :gmail, "MySecretId", "MySecretKey", {:redirect_path => "/invites/gmail/contact_callback" }
7 end
'invites_controller.rb' controller code:
3 def index
4 #contacts = request.env['omnicontacts.contacts']
5 respond_to do |format|
6 format.html
7 end
8 end
Routes.rb code:
3 get "/invites/:provider/contact_callback" => "invites#index"
4 get "/contacts/failure" => "invites#failure"
5 root :to => "invites#index"
Here's the redirects uri of the google application:
https://www.example.com/oauth2callback
https://127.0.0.1:3000/invites/gmail/contact_callback
https://127.0.0.1/invites/gmail/contact_callback
How can I solve this?
I know this question is kind of old but this is happening because gmail won't allow you to have ip addresses as redirect uris. You will need to add something like this. yourmachine.example.com:3000/invites/gmail/contact_callback
And then in your hosts file you will need to add the following line:
192.168.1.2 devmachine yourmachine.example.com
Where 192.168.1.X, is your local ip address.
You should now be able to access your local rails application by going to this url:yourmachine.example.com:3000 in your local machine. Google will now accept this redirect_uri as it's a valid hostname and you should be able to get your contacts back.

How to integrate SoundCloud in Ruby on Rails?

I am new to RubyOnRails and SoundCloud.
I want to integrate SoundCloud API in my ruby on rails application.
For this I have registered on SoundCloud And I got the ClientID and ClientSecret. Also I have downloaded the SDK.
Now I have copied the files and folders from lib and spec directory to my applications lib and spec directory. Also I have added gem 'soundcloud' in the Gemfile.
After this I made simple code (copied from doc) in My Interactor:
# register a client with YOUR_CLIENT_ID as client_id_
client = SoundCloud.new(:client_id => YOUR_CLIENT_ID)
# get 10 hottest tracks
tracks = client.get('/tracks', :limit => 10, :order => 'hotness')
# print each link
tracks.each do |track|
puts track.permalink_url
end
But here I'm getting the error -
uninitialized constant MyApp::Interactors::MyInteractor::MyAction::SoundCloud
I followed the steps from APIDoc. Is there any step by step example for integrating SoundCloud in Ruby on Rails so that I can follow?
How can I resolve this error?
MyInteracor.rb
module MyApp
module Interactors
module MyInteractor
class MyAction < Struct.new(:user, :params)
def run
# SoundCloud
# register a client with YOUR_CLIENT_ID as client_id_
client = SoundCloud.new(:client_id => 'my-client-id')
# get 10 hottest tracks
tracks = client.get('/tracks', :limit => 10, :order => 'hotness')
# print each link
tracks.each do |track|
puts track.permalink_url
end
end
end
end
end
end
There's a typo in the soundcloud github page change the line:
client = SoundCloud.new(:client_id => 'my-client-id')
to
client = Soundcloud.new(:client_id => 'my-client-id')
[notice the lowercase c in Soundcloud]
Also you are going to need your client secret for SoundCloud's API to verify you.
Perhaps put client method and in it have client = SoundCloud.new(your-client-id,your-secret-key-your-redirect-uri) in a controller or helper with your client_id, client_secret, and redirect uri values protected in a .env file.
I think by leaving out your redirect_uri and client secret you might be getting this error in MyInteractor.rb
Hope this helps

How to implement badgeville in ruby on rails

Can anyone tell me how to implement badgeville in ruby on rails?
EDIT:
how can I apply this on ruby on rails?
https://github.com/badgeville/badgeville-ruby
I'm not sure how this particular gem work, but normally it should work with following steps
create a file called 'badgeville.rb' inside app/config/initializers
add the following code to badgeville.rb
BadgevilleBerlin::Config.conf(
:host_name => "http://example.com",
:api_key => MY_API_KEY)
restart
then you should be able to use the following commands inside your
controllers/ models
Ex:
new_site = BadgevilleBerlin::Site.new(
:name => "My Website",
:url => "mydomain.com",
:network_id => MY_NETWORK_ID )
success = new_site.save

instagram-ruby-gem undefined method `query_values'

Hi there i have been working on a project that graps the users instagram photos and let them to download it. To authenticate i use the gem called instagram-ruby-gem
which is an offical ruby gem for instagram
def instagram_callback
response = Instagram.get_access_token(params[:code], :redirect_uri => "http://0.0.0.0:3000/oauth/callback")
client = Instagram.client(:access_token => response.access_token)
user = client.user
raise client.user_recent_media.inspect
end
def instagram_login
return redirect_to Instagram.authorize_url(:redirect_uri => "http://0.0.0.0:3000/oauth/callback")
end
When the instagram callback method is called there is an errors pops-up
undefined method `query_values' for #URI::HTTPS:0x0000010441f028 and it shows the line
response = Instagram.get_access_token(params[:code], :redirect_uri => "http://0.0.0.0:3000/oauth/callback")
I guess this is a gem bug maybe not but i am having the problem there is a issue about about it in the git-hub page did any one have any solution for this ?
I commented workaround on github page.
Please try to use faraday version "0.7.6".

how to get oauth access token for facebook using ruby

Am trying to get oauth access token for facebook programmatically in ruby.
My code is as follows:
client = OAuth2::Client.new(
APP_ID,
SECRET_ID,
:authorize_url => "/dialog/oauth",
:token_url => "/oauth/access_token",
:site => "https://www.facebook.com/"
)
code = client.auth_code.authorize_url(:redirect_uri => "http://www.facebook.com/")
token = client.auth_code.get_token(code, :redirect_uri => "https://graph.facebook.com/")
OAuth2::AccessToken.new(client, token.token, {:mode => :query, :param_name =>"oauth_token"})
When i try to run the above ruby code, i'm getting the following exception
https://www.facebook.com/dialog/oauth?response_type=code&client_id=APP_ID
51&redirect_uri=http%3A%2F%2Fwww.facebook.com%2F
/home/ec2-user/.rvm/gems/ruby-1.9.3-p0#samples/gems/oauth2-0.5.2/lib/oauth2/clie
nt.rb:129:in `get_token': OAuth2::Error (OAuth2::Error)
from /home/ec2-user/.rvm/gems/ruby-1.9.3-p0#samples/gems/oauth2-0.5.2/li
b/oauth2/strategy/auth_code.rb:29:in `get_token'
from oauth.rb:16:in `<main>'
Any help is greatly appreciated as I have spent more than a day while trying to sort this out.
Have you tried to put as redirect_uri instead of localhost:3000 your real IP address ex. 231.61.233.57:3000? Additionally you could try to use ssh tunneling for testing purposes so your localhost application will be available worldwide. Check this out http://progrium.com/localtunnel/ .
When you will get ip address from this tool try to set redirect_uri param to it.

Resources