I find article about Post on Google Plus on
https://developers.google.com/+/api/latest/moments/insert
From that we find example shows how to create moment.
$moment_body = new Google_Moment();
$moment_body->setType("http://schemas.google.com/AddActivity");
$item_scope = new Google_ItemScope();
$item_scope->setId("target-id-1");
$item_scope->setType("http://schemas.google.com/AddActivity");
$item_scope->setName("The Google+ Platform");
$item_scope->setDescription("A page that describes just how awesome Google+ is!");
$item_scope->setImage("https://developers.google.com/+/plugins/snippet/examples/thing.png");
$moment_body->setTarget($item_scope);
$momentResult = $plus->moments->insert('me', 'vault', $moment_body);
From Google APIs Client Library for PHP i'm not find api about Google_ItemScope, and Google_Moment is Google_PlusMomentsService.php. So can not try this example.
Anybody know about this? Or have solution can me try auto post on google plus using PHP?
Thanks
i also found same problem, in new google + api they change class name try below code
$plusservicemoment = new Google_Service_Plus_Moment();
$plusservicemoment->setType("http://schemas.google.com/AddActivity");
$plusService = new Google_Service_Plus($client);
$item_scope = new Google_Service_Plus_ItemScope();
$item_scope->setId('12345');
$item_scope->setType("http://schemas.google.com/AddActivity");
$item_scope->setName("yout site/api name");
$item_scope->setDescription("A page that describes just how html work!");
//$item_scope->setImage("full image path here");
$plusservicemoment->setTarget($item_scope);
$result = $plusService->moments->insert('me','vault',$plusservicemoment);
Related
I try to get the customer manager link from Google Ads API PHP Lib. But they except the Resource_name. What's that ?
$client->getCustomerManagerLinkServiceClient()->getCustomerManagerLink(resourceName)->getManagerLinkId();
They have no documentation in PHP for this new service. They have some examples but the one i need doesn't exist yet.
I try to merge an existing Ads/Adwords Customer to My Google Ads Manager (MCC). But i don't know what i'm suppose to do.
Thanks for help.
Cheers.
Someone can help me ?
This is my code if you want to see more.
The challenge is to use only the Google Ads Api Library from this Github : https://github.com/googleads/google-ads-php
I don't want to use the Google Adwords API, juste Google Ads API.
$oAuth2Credential = (new OAuth2TokenBuilder())
->fromFile('google_ads_php.ini')
->withRefreshToken(self::getRefreshToken())
->build();
$googleAds = (new GoogleAdsClientBuilder())
->fromFile('google_ads_php.ini')
->withOAuth2Credential($oAuth2Credential)
->build();
$resourceName = Customer ID;
$customerManagerLinkOperation = new \Google\Ads\GoogleAds\V0\Services\CustomerManagerLinkOperation([
'manager_customer' => new StringValue(['value' => $googleAds->getLoginCustomerId()])
]);
$googleAds->getCustomerManagerLinkServiceClient()->mutateCustomerManagerLink($resourceName,$customerManagerLinkOperation);
I'm not familiar with the php library but with the python library you can use the GoogleAdsService together with google ads query to retrieve the data.
Example:
cutomer_id = '11111111111'
q = ('SELECT customer_manager_link.manager_customer, '
'customer_manager_link.status '
'FROM customer_manager_link'
result = ga_service.search(customer_id, q)
I think the same should be possible in php. Something like this:
$googleAdsServiceClient = $googleAdsClient->getGoogleAdsServiceClient();
$customerId = 11111111111
$query = 'SELECT customer_manager_link.manager_customer, '
.'customer_manager_link.status '
.'FROM customer_manager_link'
$response = $googleAdsServiceClient->search($customerId, $query);
I am trying to add an entry with this sample of code :
<?php
$service = new \Google_Service_Calendar($client);
$calendarListEntry = new \Google_Service_Calendar_CalendarListEntry();
$calendarListEntry->setId($calendarId);
$calendarListEntry->setHidden(false);
$calendarListEntry->setSelected(true);
$calendarListEntry = $service->calendarList->insert($calendarListEntry);
The calendar is inserted but not shown on the Gmail Android App. I have to go to settings to display it.
I thought with setHidden() and setSelected() it would work but it didn't change anything. Plus, $calendarListEntry returned after insert has hidden = null.
Any thoughts ?
I try to implement People API, after successfully OAuth2, when try to load people, error is:
Undefined property: Google_Service_People_Resource_People::$connections
This is lines who produce error:
$people_service = new Google_Service_People($client);
$connections = $people_service->people->connections->listConnections('people/me');
Am going by this tutorial https://developers.google.com/people/v1/getting-started,
and this: https://developers.google.com/people/v1/requests.
Thanks
I think you are looking for...
$connections = $people_service->people_connections->listPeopleConnections('people/me');
We've written a PHP Google People API library that might help. It makes implementing access to Google Contacts via the Google People API much easier than using Google's own library.
Link: https://github.com/rapidwebltd/php-google-people-api
Example Usage
Usage
Retrieve all contacts
// Retrieval all contacts
foreach($people->all() as $contact) {
echo $contact->resourceName.' - ';
if ($contact->names) {
echo $contact->names[0]->displayName;
}
echo PHP_EOL;
}
Retrieve a single contact
// Retrieve single contact (by resource name)
$contact = $people->get('people/c8055020007701654287');
Create a new contact
// Create new contact
$contact = new Contact($people);
$contact->names[0] = new stdClass;
$contact->names[0]->givenName = 'Testy';
$contact->names[0]->familyName = 'McTest Test';
$contact->save();
Update a contact
// Update contact
$contact->names[0]->familyName = 'McTest';
$contact->save();
Delete a contact
// Delete contact
$contact->delete();
I've been trying to post an image with a simple message onto twitter using PHP and twitteroauth.php.
However, every time I run my code, I only get the $tweetMessage published on the twitter feed without any image.
I searched and searched and read their own documentation but don't even get me started on their own documentation! its like someone who's had a sleepwalk was writing their documentation. Just a bunch of jargon..
And most of the information on STO is either outdated or pointing to a library!
I do not want to use any library as I will have to try to learn someone else's code as well and Surely twitter would allow publishing photo's using their own API without the use of any third party Library?!
Any way, This is my full code:
// Include twitteroauth
require_once('inc/twitteroauth.php');
// Set keys
$consumerKey = 'xxxxxxxxxxxxxxxxxxx';
$consumerSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$accessToken = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
$accessTokenSecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx';
// Create object
$tweet = new TwitterOAuth($consumerKey, $consumerSecret, $accessToken, $accessTokenSecret);
// Set status message
$tweetMessage = 'This is a tweet to my Twitter account via PHP.';
$image_path="https://www.google.co.uk/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png";
$handle = fopen($image_path,'rb');
$image = fread($handle,filesize($image_path));
fclose($handle);
// Check for 140 characters
if(strlen($tweetMessage) <= 140)
{
// Post the status message
$tweet->post('statuses/update', array('media[]' => "{$image};type=image/jpeg;filename={$image_path}", 'status' => $tweetMessage));
}
Could someone please advise on this issue?
Thanks in advance.
EDIT:
I've changed my code to the following and I get this error:
{"errors":[{"code":195,"message":"Missing or invalid url parameter."}]}
But I'm sure the image is on the specified URL/directory!
This is the code:
require_once 'inc/twitteroauth.php';
define("CONSUMER_KEY", "xxxxxxxxxxxxxxxxx");
define("CONSUMER_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_TOKEN", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
define("OAUTH_SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
$connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, OAUTH_TOKEN, OAUTH_SECRET);
$content = $connection->get('images/sign-in-with-twitter-l.png');
$image = 'images/sign-in-with-twitter-l.png';
$status_message = 'Attaching an image to a tweet';
$status = $connection->post('statuses/update_with_media', array('status' => $status_message, 'media[]' => file_get_contents($image)));
echo json_encode($status);
Any idea why this error is being shown?
Uploading media to Twitter is slightly complicated. Essentially, it's a three stage process.
Upload the photo to Twitter.
Receive a media_id back from Twitter.
Post your status and media_id to Twitter.
This is described in great detail at https://dev.twitter.com/rest/reference/post/media/upload
Generally speaking, it is easier for use to use a library like CodeBird as they've already done the hard work of finding all the edge cases.
But, assuming you don't want to do that...
POST the image to /1.1/media/upload.json
Receive back some JSON like
{
"media_id": 553656900508606464,
"media_id_string": "553656900508606464",
"size": 998865,
"image": {
"w": 2234,
"h": 1873,
"image_type": "image/jpeg"
}
}
* Use that media_id_string when you post the status. e.g.
tweet->post('statuses/update', array('media_ids' => $media_id_string, 'status' => $tweetMessage));
Hopefully that gives you enough to understand what's going on.
I solved it like this:
$tweet_img = 'Path/to/image';
$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);
Horrible twitter API documentation needs improving!! it needs to be written by humans as opposed to a bunch of sleepwalking zombies!!!
This is a very frustrating situation that they put us in when we try to use their API...
They either need stop their API support and remove it all from the public or simply improve their documentation and write it for the public and not just for their own use using jargon words.
Any way, the above code works just fine using the latest twitteroauth
I hope this helps others in my situation.
I feel like i wasted 5 hours for something that should be clear and mentioned in plain English on their site!!!
Rant and Answer over & good luck.. :)
You're supposed to be able to do this, through something like this:
$snippet = new Google_VideoSnippet();
$snippet->setTitle("some title");
$snippet->setDescription("some description);
...
$status = new Google_VideoStatus();
$status->setPrivacyStatus("public");
$status->setLicense("creativeCommon");
$video = new Google_Video();
$video->setSnippet($snippet);
$video->setStatus($status);
and so on. Yes, you'd think that the value for setLicense would be "creativeCommons", but it's not (https://developers.google.com/youtube/v3/docs/videos#resource). Using "creativeCommons" or anything other than "youtube" and "creativeCommon" results in a "(500) Bad Request" response.
But the real problem is that, for me anyway, once the video gets up to YouTube (which it is doing), I get a YouTube license regardless of whether I've specified "youtube" or "creativeCommon". So: is this supposed to work / am I doing it wrong / are there any ideas out there?
Not sure if this helps anyone but (a few years later) it seems to work to set the licencetype to creativeCommon using the javascript-version of the api (v3).
UploadVideo.prototype.uploadFile = function(file) {
var metadata = {
status: {
privacyStatus: $('#privacy-status option:selected').text(),
license: "creativeCommon"
}
};