Issue with sending direct message to someone with API for Twitter - php

Hey guys I am using the following:
function confirm($x, $y)
{
$inerlevelWatch = $x;
$NewDirectMessage = $y;
$directmessconect = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $currentTwitteroauth, $currentTwitteroauthsecret);
$parameters = array('screen_name' => $inerlevelWatch, 'text' => $NewDirectMessage);
$method = 'direct_messages/new';
$directmessconect->post($method, $parameters);
}
So I give the $innerlevelWatch a screen_name so lets say, Joe and than the new direct message that is passed to $NewDirectMessage = 'testing'. I create new connection just for the sending of the message inside this function and set the parameters. Set the method and then make the post.
The issue is, It does not seem to actually send and I am not sure why, so if you could give me a hand I would appreciate it!

`$consumerKey="your consumerKey";
$consumerSecret ="consumerSecret";
$accessToken ="accessToken ";
$accessTokenSecret ="accessTokenSecret";`
// Create object
`$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);`
// Set status message
`$tweetMessage="message";`
`$scrren_name='abc';`
`if(strlen($tweetMessage)<=140)
{
$tweet->post('direct_messages/new', array('screen_name' => $scrren_name,'text'=>$tweetMessage));
}`
hope it help you

Related

Google Search Console API, URL Inspection

I want to use the Google Search Console API to check if an url is indexed.
$client = new Google_Client();
$client->setAuthConfig( json_decode( $json, true ));
$scopes = ['https://www.googleapis.com/auth/webmasters','https://www.googleapis.com/auth/webmasters.readonly'];
$client->addScope($scopes);
$searchConsole = new Google_Service_SearchConsole($client);
$urlRequest = new \Google_Service_SearchConsole_InspectUrlIndexRequest();
$urlRequest->setInspectionUrl($url);
$urlRequest->setLanguageCode('fr');
$urlRequest->setSiteUrl('sc-domain:'.$url);
$urlIndex = new \Google_Service_SearchConsole_Resource_UrlInspectionIndex();
The problem is when I try to create an UrlInspectionIndex to make an inspect() with $urlRequest I get an Exception in the constructor of vendor/google/apiclient/src/Service/Resource.php:66
I don't know what those arguments are. Hope anyone would help me, thank you.
I got it to work like this:
$service = new Google_Service_SearchConsole($client);
$query = new Google_Service_SearchConsole_InspectUrlIndexRequest();
$query->setSiteUrl("https://$domain/");
$query->setInspectionUrl("https://$domain/$page");
$results = $service->urlInspection_index->inspect($query);

twinfield API integration with laravel

Twinfield is an online financial accounting software package for small and medium enterprises, produced and maintained by Twinfield International, based in The Netherlands. It is used by over 15,000 subscribers in 20 countries.
I want to integrate its API. I have install laravel and create some basic API, but its huge. How and where the integration example links? Please help me.
This is not the full code but gives you the login for the twinfield. I am also stuck because many libraries are given for twinfield but not give any sample code for it. There is no document provide for PHP integration. I am very disappointed with twinfield. Even if you have test account and it will disable than it will permanent disable. Here the jsonresponse is custom made so you can call only $e->getMessage() if you have any error related it.
public function login(\Illuminate\Http\Request $request){
$user = $request->input('user');
$password = $request->input('password');
$org = $request->input('organisation');
$params = array(
'user' => $user,
'password' => $password,
'organisation' => $org
);
// login => Set the param array and send to the logon
try
{
$session = new \SoapClient("https://login.twinfield.com/webservices/session.asmx?wsdl", array('trace' => 1));
$result = $session->logon($params);
// echo '<pre>';print_r($result);
$cluster = $result->cluster;
$qq = new domDocument();
$qq->loadXML($session->__getLastResponse());
$sessionID = $qq->getElementsByTagName('SessionID')->item(0)->textContent;
//echo $sessionID;
$newurl = $cluster . '/webservices/processxml.asmx?wsdl';
try
{
$client = new \SoapClient($newurl);
$data = new \SoapHeader('http://www.twinfield.com/', 'Header', array('SessionID'=> $sessionID));
$jsonResponse = JsonResponse::success($data);
}
catch (SoapFault $e)
{
$jsonResponse = empty($e->getMessage()) ? JsonResponse::error(class_basename($e)) : JsonResponse::error($e->getMessage());
}
}
catch (SoapFault $e)
{
$jsonResponse = empty($e->getMessage()) ? JsonResponse::error(class_basename($e)) : JsonResponse::error($e->getMessage());
}
return $jsonResponse;
}
Some code are given in this link too. You will integrate it via https://github.com/php-twinfield/twinfield but you have to work a lot. I am also working on it, if anything you need plz let me know.

How to use Google MyBusiness API in php

I am using Google MyBsiness API for fetching all business reviews.
But I am unable to familer with PHP syntax and GET, POST method use in MYBusiness.
After Oath here are code i am using to fetch review
$mybusinessService = new Google_Service_Mybusiness($client);
$accessToken = file_get_contents($credentialsPath);
$reviews = $mybusinessService->accounts_locations_reviews;
echo '<pre>';print_r($reviews->get('ArtechDev'));exit;
But i am getting error 404 (Fatal error: Uncaught exception 'Google_Service_Exception' with message)
I am sure that I don't know how to pass param and which things needed for it. I am logged in as account which having Location 'ArtechDev' also please
let me know that where can i call
https://mybusiness.googleapis.com/v3/accounts/account_name/locations/location_name/reviews
Thanks
I hope you had found the answer to your question a long time ago, anyway I'll leave this hoping help someone else.
/*$accounts previusly populate*/
/*(GMB - v4)*/
$credentials_f = "google_my_business_credentials_file.json";
$client = new Google_Client();
$client->setApplicationName($aplicattion_name);
$client->setDeveloperKey($developer_key);
$client->setAuthConfig($credentials_f);
$client->setScopes("https://www.googleapis.com/auth/plus.business.manage");
$client->setSubject($accounts->email);
$token = $client->refreshToken($accounts->refresh_token);
$client->authorize();
$locationName = "accounts/#######/locations/########";
$mybusinessService = new Google_Service_Mybusiness($client);
$reviews = $mybusinessService->accounts_locations_reviews;
do{
$listReviewsResponse = $reviews->listAccountsLocationsReviews($locationName, array('pageSize' => 100,
'pageToken' => $listReviewsResponse->nextPageToken));
$reviewsList = $listReviewsResponse->getReviews();
foreach ($reviewsList as $index => $review) {
/*Accesing $review Object
* $review->createTime;
* $review->updateTime;
* $review->starRating;
* $review->reviewer->displayName;
* $review->reviewReply->comment;
* $review->getReviewReply()->getComment();
* $review->getReviewReply()->getUpdateTime();
*/
}
}while($listReviewsResponse->nextPageToken);
$acounts comes from:
$mybusinessService = new Google_Service_MyBusiness(...);
$accounts = $mybusinessService->accounts;

How to post feeds to twitter?

I want to post some text automatically to my application twitter account. I create an account for that and take all the needed information and write a php code for it. it is simple code:
I made it just to test the post ability :
<?php
require_once 'oauth/twitteroauth.php';
$message = "hiiiiiii"; #actual message to twitter
define("CONSUMER_KEY", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("CONSUMER_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_TOKEN", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
print_r($connection);
$content = $connection->get('account/verify_credentials');
//print_r($content);
$connection->post('statuses/update', array('status' => $message));
?>
I get the information from the account so i think the connection is working but why i can not post any thing? i tried to post this message but after executing this code nothing happened on my twitter no new tweet is shown????
$connection->post is a method :
/**
* POST wrapper for oAuthRequest.
*/
function post($url, $parameters = array()) {
$response = $this->oAuthRequest($url, 'POST', $parameters);
if ($this->format === 'json' && $this->decode_json) {
return json_decode($response);
}
return $response;
}
My first port of call if you are able to receive information from the account using those credentials, would be that your app has read AND write (posting) permissions:
Go to dev.twitter.com/apps. Select your app, then under 'settings' -->
'application type' you will find what you need.
Although that didn't work, no matter what you changed in your code posting to your account through this app wouldn't work as that functionality was outside the permissions you set yourself. So now we know that you're able to post:
Change
$connection->post('statuses/update', array('status' => $message));
To
$result = $connection->post('statuses/update', array('status' => $message));
Then see what the value of $result is. This might provide some clues
Ok so the response is telling you, you still don't have permissions, you need to regenerate your token and access credentials then update your code with them:
define("CONSUMER_KEY", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("CONSUMER_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_TOKEN", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
Those credentials still have the previous permissions attached to them, when you request new token, it will reference the new permissions and allow you to post.

2 legged oath request without command line

i want to make an 2 legged oauth yql request with php.
So far:
// Include the PHP SDK.
include_once("yosdk/lib/Yahoo.inc");
// Define constants to store your API Key (Consumer Key) and
// Shared Secret (Consumer Secret).
define("API_KEY","her_comes the key");
define("SHARED_SECRET","here_comes_the_secret");
$two_legged_app = new YahooApplication(API_KEY,SHARED_SECRET);
$stock_query = "elect * from ......";
$stockResponse = $two_legged_app->query($stock_query);
var_dump($stockrResponse);
But the problem is, that i dont want to query the command line..... i just want to oauth with the api key i got and use the url directly i got of the command when i typed in yql....
like this:
$url='http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20('+url_stocks+')&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys';
(i edited the url that came out my wishes for).Please dont ask why i dont use the command to query (long story). i would be pleased by getting some help.
thanks.
solved it:
http://code.google.com/p/oauth-php/wiki/ConsumerHowTo
include_once "oauth/library/OAuthStore.php";
include_once"oauth/library/OAuthRequester.php";
$key_1 = "your_key"; $secret_1 = "your_secret";
$ticks="%22AAPL%22%2C%22MSFT%22";
$options = array( 'consumer_key' => $key_1, 'consumer_secret' =>
$secret_1 ); OAuthStore::instance("2Leg", $options );
$url =
"http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol%20in%20('$ticks')&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys";
// this is the URL of the request $method = "GET"; // you can also use
POST instead $params = null;
try {
// Obtain a request object for the request we want to make
$request = new OAuthRequester($url, $method, $params);
// Sign the request, perform a curl request and return the results,
// throws OAuthException2 exception on an error
// $result is an array of the form: array ('code'=>int, 'headers'=>array(), 'body'=>string)
$result = $request->doRequest();
$response = $result['body'];
$resp_array=json_decode($response,TRUE);
echo $resp_array['query']['results']['quote'][1]['symbol']; // MSFT
} catch(OAuthException2 $e) { }

Categories