Linkedin: How to make api calls using access token? - zend-framework

I am storing the linkedin access token in database. This is the token that is stored in my database:
oauth_token=xxxxxxxxxxxxxxxxxxx&oauth_token_secret=xxxxxxxxxxxxxxxxxxx&oauth_expires_in=5183998&oauth_authorization_expires_in=5183998
I want to retrieve the linkedin connections using this access token. I am trying to make a call like this:
$a = new Zend_Oauth_Token_Access();
$client = $a->getHttpClient( array(
'siteUrl' => LIN_SITE_URL,
'callbackUrl' => LIN_SITE_CALLBACK_URL,
'requestTokenUrl' => LIN_REQUEST_TOKEN_URL,
'userAuthorizationUrl' => LIN_USER_AUTHORIZATION_URL,
'accessTokenUrl' => LIN_ACCESS_TOKEN_URL,
'consumerKey' => LIN_CONSUMER_KEY,
'consumerSecret' => LIN_CONSUMER_SECRET
) );
$client->setUri('http://api.linkedin.com/v1/people/~/connections:(id,first-name,last-name,picture-url)');
$client->setParameterGet('token',$linToken);
$client->setMethod(Zend_Http_Client::GET);
$response = $client->request();
$content = $response->getBody();
$data = json_decode(Zend_Json::fromXml($content, false));
print_r($data); echo "<br/>";
The error i am getting here is:
stdClass Object ( [error] => stdClass Object ( [status] => 404 [timestamp] => 1349429996351 [request-id] => 8U8A1UNF1V [error-code] => 0 [message] => Could not find person based on: ~ ) )
Is this the correct way to make a call or am i doing something wrong here. I am using zend framework.
Thanks.

I was able to solve the problem by passing the outh_token and outh_token_secret as an array to the setParams() of Zend_Oauth_Token_Access as below:
$a = new Zend_Oauth_Token_Access;
$a->setParams(array(
'oauth_token' => 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
'oauth_token_secret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxx'
));

In your code example I don't see where you're setting the access token and secret. I just see that you're instantiating the $a variable:
$a = new Zend_Oauth_Token_Access();
Are you retrieving the access token and secret from you database then setting it to the $a variable? Something like this:
$a->setToken($row['token'])
->setTokenSecret($row['secret']);
By the way, this is a good reference for using Zend and LinkedIn: http://www.contentwithstyle.co.uk/content/linkedin-and-zendoauth/

Related

Does tweet_mode=extended work with the Twitter statuses/user_timeline API?

There is no mention of tweet_mode at https://developer.twitter.com/en/docs/tweets/timelines/api-reference/get-statuses-user_timeline.html
I am wondering if perhaps I am using the wrong API to be able to take advantage of tweet_mode?
In my application, I supplied the tweet_mode=extended argument and it had no effect. My code...
// Load the Tweets.
$args = array(
'screen_name' => $username,
'exclude_replies' => 'true',
'include_rts' => 'true',
'tweet_mode' => 'extended',
'count' => $numitems,
);
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET);
$tweets = $connection->get('statuses/user_timeline', $args);
if (!empty($tweets)) {
foreach ($tweets as $tweet) {
$text = $tweet->full_text;
// etcetera
Yes, you can use tweet_mode with the statuses/user_timeline API. Retweets are a special case, though. Check the retweeted_status object, as described at https://dev.to/kehers/formatting-tweets-a-look-at-extended-tweets-retweets-and-quotes-n5j
In short, if a tweet is a retweet, the extended tweet must be accessed at $tweet->retweeted_status->full_text. Thus, it's necessary in your code to check if each tweet object has a retweeted_status property.

Missing or invalid url parameter while posting image with twitter API

I am trying to post image on twitter. Image is already in my server. Here is my code
$tweet_img = '/home/voucherscode/public_html/editsocial/'.$tweet_img;
$returnT = $connection->post('statuses/update_with_media', array(
'media[]' => file_get_contents($tweet_img),
'status' => "$tweet_msg"
));
But I am response as
stdClass Object(
[errors] => Array
(
[0] => stdClass Object
(
[code] => 195
[message] => Missing or invalid url parameter.
)
))
Please help.
I got the issue. I was using old twitteroauth and on that post function has not multipart parameter.
I replaced my twitteroauth with https://github.com/tomi-heiskanen/twitteroauth/blob/77795ff40e4ec914bab4604e7063fa70a27077d4/twitteroauth/twitteroauth.php and it works with below code.
$tweet_img = '/home/voucherscode/public_html/editsocial/'.$tweet_img;
$handle = fopen($tweet_img,'rb');
$image = fread($handle,filesize($tweet_img));
fclose($handle);
$parameters = array('media[]' => "{$image};type=image/jpeg;filename={$tweet_img}",'status' => 'Picture time');
$returnT = $connection->post('statuses/update_with_media', $parameters, true);

Reading data from Facebook graphObject

A user has accepted my Facebook app. I can now access some of their data. It is returned as a graphObject, which contains something like:
Facebook\GraphObject Object ( [backingData:protected] => Array ( [id] => 11111 [first_name] => Bob [gender] => male [last_name] => Builder [link] => https://www.facebook.com/app_scoped_user_id/11111/ [locale] => de_DE [name] => Bob Builder [timezone] => 2 [updated_time] => 2014-02-14T14:35:54+0000 [verified] => 1 ) )
Unfortunately I cannot get at the data inside this object. Reading it like an array throws an error:
$fbid = $graphObject['id']; // Cannot use object of type Facebook\GraphObject as array
$fbid = $graphObject->id; // Undefined property: Facebook\GraphObject::$id
How can I get at the ID?
If you have casted the response as a GraphObject by using one of the following two methods:
// Get the response typed as a GraphLocation
$loc = $response->getGraphObject(GraphLocation::className());
// or convert the base object previously accessed
// $loc = $object->cast(GraphLocation::className());
You can use the Get properties of the graph object, depending on what kind of object you've casted it as... here's an example for the GraphUser Object:
echo $user->getName();
Or, if you know the name of the property (as shown in the base data), you can use getProperty():
echo $object->getProperty('name');
So in your example, you can use the following to get the id property:
echo $user->getProperty('id');
More examples and documentation here
In the New version of Graph API getProperty does not work.
For the New version Graph API v2.5 of Facebook Read read data as below :
$fb = new \Facebook\Facebook([
'app_id' => 'APPIDHERE',
'app_secret' => 'SECRET HERE',
'default_graph_version' => 'v2.5',
]);
$asscee_t ="ACCESS TOKEN HERE";
$response = $fb->get('/me/friends', $asscee_t);
$get_data = $response->getDecodedBody(); // for Array resonse
//$get_data = $response->getDecodedBody(); // For Json format result only
echo $get_data['summary']['total_count']; die; // Get total number of Friends
Note that from API version >= 5.0.0 getProperty() has been renamed to getField(). It will be removed from >= v6. So
Instead of
$user->getProperty('name')
Use
$user->getField('name')

Can someone provide a php sample using nusoap/sugarcrm api to create an acct/lead in sugarcrn?

Can someone provide a sample code chunk of php using the sugarcrm API/nusoap for adding creating an acct. and then linking a lead to the acct?
I've got a sample function that adds a lead, and I can see how to create an acct, but I can't see how to tie a lead to the acct, to simulate the subpanel process in the sugarcrm acct/subpanel process.
thanks
// Create a new Lead, return the SOAP result
function createLead($data)
{
// Parse the data and store it into a name/value list
// which will then pe passed on to Sugar via SOAP
$name_value_list = array();
foreach($data as $key => $value)
array_push($name_value_list, array('name' => $key, 'value' => $value));
// Fire the set_entry call to the Leads module
$result = $this->soap->call('set_entry', array(
'session' => $this->session,
'module_name' => 'Leads',
'name_value_list' => $name_value_list
));
return $result;
}
$result = $sugar->createLead(array(
'lead_source' => 'Web Site',
'lead_source_description' => 'Inquiry form on the website',
'lead_status' => 'New',
'first_name' => $_POST['first_name'],
'last_name' => $_POST['last_name'],
'email1' => $_POST['email'],
'description' => $_POST['message']
));
You need to find the ID for the account and assign that ID to whatever the account_id field name is in the Lead Module. I have run into a couple things like this before and I have found it easier to go straight to the Sugar database. So, write a statement that will return the account is, for example: SELECT id WHERE something_in_the_account_table = something else;
Then you can assign that id in your $result array. I hope it helps. I didn't have any code or documentation in front of me or I would have helped more.

Zend Twitter: Connecting

I have the following code:
$twitter = new Zend_Service_Twitter(array('username' => $this->site->twitter_username, 'accessToken' => $this->site->twitter_password));
$response = $twitter->account->verifyCredentials();
print_r($response);
$twitter->account->endSession();
My username is my Login Username on twitter, my $this->site->twitter_password is my Access Token (oauth_token)
Yet I get:
Zend_Rest_Client_Result Object ( [_sxml:protected] => SimpleXMLElement Object ( [request] => /account/verify_credentials.xml [error] => Could not authenticate you. ) [_errstr:protected] => )
I'm unsure where I'm going wrong, any ideas?
I recently blogged about this and have included some instructions that should get you going, let me know if you need any more pointers.
PHP Using Zend framework to display new tweets as KDE notifications