How to get posts from google+ stream - google-plus

I need to take google+ posts from stream and publish them on my site. I know that google doesn't have api to do that. But some services like suck http://www.friendsplus.me/ can do that. Does anybody know how?

First, you should go to google apis and enable Google Plus services. Here it comes;
Go to API Console.
Select Services
Enable Google+ API services.
Select API Access
Simple API Access > grab your API Key.
And you can use following code for read stream posts;
<?php
$google_plus_id = '106670447018211124292';
$appKey = 'app_key_here';
$streams = json_decode(file_get_contents('https://www.googleapis.com/plus/v1/people/' . $google_plus_id . '/activities/public?key='. $appKey));
foreach ($streams->items as $item) {
echo $item->title .
date('F jS Y # H:i:s',strtotime($item->published)) .
$item->object->content .
'<br />';
}
You can also test this code's job on google api console.
1.) Go to API Console and select Google+ API
2.) Select APIs menu on left menu
3.) Click on public.activities.list on that page
4.) Enter your profile id in userId section and type "public" on collection section then click Execute. You can see below;

Depending on your exact needs, the Google+ API documented at https://developers.google.com/+/api/ may do what you need. It can show you the public posts from a specific user. You can also see some sample code to illustrate this at https://bakingdisasters.com/.
What it can't do, however, is show you the private posts from that user that are permitted to you, or show you all of the posts (public or private) that you may have seen.

Related

How can a webhook identify USER_IDs?

I'm developing a webhook, and I want it to be able to #mention specific users. The simple message format specifies using the format of <users/123456789012345> to #mention a specific users. Since this is not a bot, it is not processing an incoming message and cannot pull the from the sender field, as suggested in the note on the developer site linked above.
How can I get the USER_ID of a user on my domain?
I am in the same boat as you. Trying to use a Webhook to mention a user.
If you inspect the HTML on https://chat.google.com, using web/dev tools, you can actually see user ID under tag data-member-id="user/bot/123456789012345"
Using the above I tried to form a webhook that mentioned the user (in my case another bot).
Unfortunately it didn't work. Passing in the string <users/123456789012345> please test came through to chat as a string literal.
It's strange because the html links and markup DO get interpreted. As mentioned here. Edit: so does <users/all>.
I'm leaving this here since your question asks for how to elicit the ID. While it may not be pretty, or much automatable, it helped me get the user ID at least.
Edit 2: It works, just not to mention my other bot for some reason. But using this method I was able to mention a human user :)
I use this for find the USER_ID but if you have another way let me know
Right click on the user and select inspect
Search for data-member-id this is your USER_ID
A webhook will not be able to pull the USER_ID of a user. As a workaround for this, you can create a service account and a bot that has access to the room and use the REST API spaces.members.list() and spaces.members.get() method.
Note: The bot will need to be added to the room.
Okay, so in order to get the UserID without having to do all of the things that you're trying to do here you need to use the Admin SDK API in google app script. Basically what you'll want to do is use your google app script as an intermediary for what you're trying to do. So you'll post something to google app script via their web exec functions on a deployed app and then have that app communicate to the google chat API via something like this:
var googlewebhookurl = 'https://chat.googleapis.com/v1/spaces/ASDFLKAJHEPQIHEWFQOEWNQWEFOINQ';
var options = {
'method': 'post',
'contentType': 'application/json',
'payload' : JSON.stringify({ text: "<users/000000000001> I see you!" })
}
UrlFetchApp.fetch(googlewebhookurl, options);
To start, you'll need to add the Admin SDK API to the services in your google app script services area. So click the plus next to "Services" and then select the Admin SDK API and click add to add it to the services, it winds up showing up in the list as "AdminDirectory" once it has been added to the services.
This is an image showing what it looks like once you've added it to the services.
Here is a link to the documentation for the Admin SDK API getting user information: https://developers.google.com/apps-script/advanced/admin-sdk-directory#get_user
You should be able to copy and paste that example function to get the information you're looking for regarding the user. I'm pasting the example code below in case something happens to this link:
/**
* Get a user by their email address and logs all of their data as a JSON string.
*/
function getUser() {
var userEmail = 'liz#example.com';
var user = AdminDirectory.Users.get(userEmail);
Logger.log('User data:\n %s', JSON.stringify(user, null, 2));
}
In order to get the user id, take the user variable that comes back and access user.id and voila! You have the ID you're looking for. From there just plaster it into a text message in google chat and you should be in business. I haven't gotten it to work with cards at all yet. I'm not seeing any documentation saying that it's supported in cards at all. For more information regarding chat messages and cards take a look at these:
https://developers.google.com/chat/api/guides/message-formats/basic
https://developers.google.com/chat/api/guides/message-formats/cards

How to apply cron jobs to Api methods that requires authntication?

Hello frinds presently i am doing manually authentication and getting user tweets and post form various api like instagram,tweeter,youtube but it requires authentication .
Now i want to automate the process and wish to run cron so i can fetch data every hour with authentication.
I know it is possible by passing access token in url methods but no idea how to do it.
first of all you need to have those access tokens. I'll explain the YouTube API and will also write other API's links. Process is similar in almost every API first you get the token then you pass it in URL.
YouTube API :
Here is a document about YouTube API which will help you create your own access key. After creating it just pass the key in URL with key=YOUR_API_KEY. You can retrieve datas from these links they might also give you an idea about how to use the api key : Videos , Channels (There are examples in the documents for JAVA, PHP and Python ). If you are using PHP you can use this curl function for authentication and retrieving datas.

Using Gdata authorization by removing hardcoded gmail credentials to get google contacts

The idea is to login through gmail and get all contacts details and also add a contact from PHP code to google contact list.
The whole flow is working well and i am getting contact list and also adding contacts with fields.
The problem is that the code has hardcoded variables where i need to set google email and password.I want to have a link to authoriZe and then get all response..
So i just need to bypass the credentials on first attempt using an API or token method and get the contact details
Please suggest if someone has gone through this issue or share examples or resourced that might help toward the solution.
Here is the code snippet...
$user = "XXX#XXX.com";
$pass = "XXX";
// Need to remove above 2 lines and combine the login on the fly API using some with further working stuff
try {
// perform login and set protocol version to 3.0
$client = Zend_Gdata_ClientLogin::getHttpClient(
$user, $pass, 'cp');
$gdata = new Zend_Gdata($client);
$gdata->setMajorProtocolVersion(3);
// perform query and get feed of all results
$query = new Zend_Gdata_Query(
'http://www.google.com/m8/feeds/contacts/default/full');
$query->maxResults = 1000;
$query->setParam('orderby', 'lastmodified');
$query->setParam('sortorder', 'descending');
$feed = $gdata->getFeed($query);
//display data in loop below....
}
Basically I want to remove the user and pwd variables and do it on the fly to get data.
Right now I am getting all contacts and also able to add a contact but the way of setting credentials is to be changed to be more secure using a token or other way..
Insead of using the username and password directly, you need to use the Google OAuth. You need to first create a project in the Google OAuth and specify correct details. Using the app created there, you can ask for permission of a user and get his contact details in the response.
How to get Google Contacts information using Google OAuth?

Using Graph API to post to fan page as the fan page (not as a user)

Need help. I have Graph API code that uses an auth token with offline permissions to post to a fan page as me. I can't seem to figure out how to get it to post to a fan page as the fan page. The API Explorer only works as an individual. When I do a "use facebook as..." for the page and try to use the explorer, it tells me it has to revert me back to being me first. So the auth token is for my personal account, not the fan page account. The auth token has the manage_pages permissions, but that just lets me post to the page as me.
Anyone have an answer or know where I can find one? Search on FB, Bing, Google all pull up nothing on this specific issue.
The point being, of course, that while I could have the automation post as me, that means that the post doesn't show as being from the page, so most people won't see it. Need adult supervision! ;)
Check out the authentication documentation under the title App Login. All the information you need is there...
You have to request an access token for the page and not for the user - then all post you make are onbehalf of the page.
https://graph.facebook.com/oauth/access_token?
client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&
grant_type=client_credentials
Fetching that url will give you the correct access token to post as your page.
To post to fanpage u not only need a manage page permission but the most importantly u need a page access token,here's the code for getting page access token.
$pages_arr = array(
'access_token'=>$access_token ,
'fields'=>'access_token'
);
// Get Page access_token
$page_token = $fb->api('/'.$pageid, 'get',$pages_arr);
$page_access_token=$page_token['access_token']; // get page access_token
// you got the page access token,now use it to do anything on page as page
See my blog post "how to post TO a page and AS the page" at http://bobbelderbos.com/2011/11/facebook-api-post-to-page-and-as-page/
Once you have the manage_pages permission each page requires its own access code.
See the blog post for further explanation, demo and code download.

Post Google Plus Stream

Any idea about how to post on our Google+ Stream using javascript or json?
I'm not searching how to use the google+ button, I need to post on the wall(or stream)
The (recently announced) Google+ API currently provides read-only access to public data. All API calls require either an OAuth 2.0 token or an API key.
Here's some information to help you get started.
http://googleplusplatform.blogspot.com/2011/09/getting-started-on-google-api.html
http://developers.google.com/+/
These two urls do what you want, but need a confirmation from the user:
https://m.google.com/app/plus/x/?v=compose&content=YOUR_TEXT
https://plus.google.com/share?url=YOUR_URL_HERE
No public API is available, so just register for the private API and check for yourself
https://services.google.com/fb/forms/plusdevelopers/
EDIT: The API is available now:
https://developers.google.com/+/
That's the downside of the Google Plus...
See here: http://code.google.com/p/google-plus-platform/issues/detail?id=41