decioferreira / omniauth-linkedin-oauth2

A LinkedIn OAuth2 strategy for OmniAuth.
MIT License
117 stars 147 forks source link

Is there any way i can post message to my connections. #7

Closed shyammohankanojia closed 11 years ago

shyammohankanojia commented 11 years ago

Im using this gem to authenticate Linkedin users.

Step 3. Make the API calls https://developer.linkedin.com/documents/authentication Im able to access my connections with this token ttps://api.linkedin.com/v1/people/~?oauth2_access_token=AQXdSP_W41_UPs5ioT_t8HESyODB4FqbkJ8LrV_5mff4gPODzOYR

Is there any way i can post message to my connections.

This is small code

require "rest-client" require 'json' require 'multi_json' require 'hashie'

def send_message(subject, body, recipient_paths) path = "http://api.linkedin.com/v1/people/~/mailbox?oauth2_access_token=AQXdSP_W41_UPs5ioT_t8HESyODB4FqbkJ8LrV_5mff4gPODzOYR"

message = {
    'content_type' => "application/json",
    'subject' => subject,
    'body' => body,
    'recipients' => {
        'values' => recipient_paths.map do |profile_path|
        { 'person' => { '_path' => "/people/#{profile_path}" } }
        end
    }
}
puts message.to_json
RestClient.post(path, message.to_json, :accept => :json)

end

send_message("Welcome to mvi","Hi testing for new message", ["wEoHBvlFX0"])

HERE IS MY OUTPUT. {"content_type":"application/json","subject":"Welcome to mvi","body":"Hi testing for new message","recipients":{"values":[{"person":{"_path":"/people/wEoHBvlFX0"}}]}} /home/localadmin/.rvm/gems/ruby-1.9.3-p392/gems/rest-client-1.6.7/lib/restclient/abstract_response.rb:48:in `return!': 401 Unauthorized (RestClient::Unauthorized)

decioferreira commented 11 years ago

Quoting http://stackoverflow.com/a/5773084

OmniAuth is meant to be used for the authentication process

Maybe you should try something like https://github.com/hexgnu/linkedin. Does this answer your question?

shyammohankanojia commented 11 years ago

Thanks I used Linkedin Gem