VK Web API (simple) - windows

I would like to call the method "photos.get" and retrieve photos from a VK community.The problem is that I am unable to view the oid i.e owner_id( one of the parameters required for the request) when I visit the URL. For example, when I browse a certain community, I end up getting a URL like "http://vk.com/picsa".Instead of this picsa, I require a number that can be passed in as an argument. How do I get the owner_id instead from the URL?

You can use groups.getById API method. It does not require any authentication:
https://api.vk.com/method/groups.getById?group_ids=picsa
You will get the default group entity in JSON format:
{
"response": [
{
"gid": 37460919,
"name": "AMERICA",
"screen_name": "picsa",
"is_closed": 0,
"type": "page",
// photos of different size go here
}
]
}
Now, you can extract the community's ID (gid) and will be able to use it in other API requests. You can get information about several communities at the same time - you need to enumarate them with commas (/method/groups.getById?group_ids=picsa,othergroup,somename).
When you work with photos.get method, keep in mind, that VK uses negative ID values for communities and pages.
For example,
/method/photos.get?owner_id=123456789 means "photos of user 123456789" and
/method/photos.get?owner_id=-123456 means "photos of community 123456".

Other way to get group id when there is no it in group link is to click on post date of any post on the wall
And in the address line you will see link like
https://vk.com/picsa?w=wall-37460919_47702
So 37460919 is group id you need

Related

Retrieving user metadata about a provisioned SoftLayer server comes back null

I'm trying to retrieve the user meta information for each machine consistently but what I'm finding is most of my machines are missing this data. I'd like to understand better what is required for this user data to be there. I'm curious if a server can be requested and provisioned without requiring user information (e.g. an API call to order a server and no user data is given). Or whether I am missing something in how I retrieve this information. Here is the basic ruby program I'm running:
user = ###
api_key = ###
client = SoftLayer::Client.new(:username => user, :api_key => api_key, :timeout => 999999)
list_of_virtual_machines = client['Account'].result_limit(i*50,50).object_mask("mask[id, billingItem[recurringFee, associatedChildren[recurringFee], orderItem[description, order[userRecord[username], id]]], userData]").getVirtualGuests
for x in 0..list_of_virtual_machines.length - 1
pp list_of_virtual_machines[i]['userData']
if list_of_virtual_machines[i]['billingItem'] && list_of_virtual_machines[i]['billingItem']['orderItem'] && list_of_virtual_machines[i]['billingItem']['orderItem']['order'] && list_of_virtual_machines[i]['billingItem']['orderItem']['order']['userRecord']
pp list_of_virtual_machines[i]['billingItem']['orderItem']['order']['userRecord']
end
end
My prints are consistently showing null. This question is related to a similar question I asked not too long ago (but the focus of that question moved towards the provisionDate):
How to get order username and provisionDate for all SoftLayer machines using Ruby?
They are missing that data because you did not added.
you can create the user data at moment to order a new server or VSI, you just have to send the data in your order request either using the createObject method or the placeOrder method. see http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/createObject
e.g.
{
"userData": [
{
"value": "someValue"
}
]
}
or you can set it after the server has been provisioned using these methods
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest/setUserMetadata
http://sldn.softlayer.com/reference/services/SoftLayer_Hardware_Server/setUserMetadata
Basically the usermetadata are useful if you are going to use a post install script. The usermetadata value is not required to order a new server
take a look this article for examples:
http://sldn.softlayer.com/blog/jarteche/getting-started-user-data-and-post-provisioning-scripts

MailChimp v3 API - Adding to Groups

Is there a way to manage a subscribers' group preference for lists in the v3 API? MailChimp documentation is a little light on the subject.
Yes, by assigning the member to an interest.
You have to find out the ID of the group (called 'interests') that you are wanting to add to. Unfortunately this cannot be found anywhere on the MailChimp dashboard.
The easiest way to find out the 'interest' ID (rather than creating a script) is to go to the MailChimp playground and then, after entering in your API key, route to...
lists > the list in question > members (in the sub-resources dropdown)
then...
load (in the actions dropdown) for any member
or
Create Members (button)
The page will load the member's details. Scroll down until you see the 'interests' array/object. There you will see the IDs. Notice they can be set to true or false.
You will have to figure out which ID relates to what 'group'/'interest' by making the call, and then looking at the member's details via your MailChimp dashboard.
So when it comes to actually making the POST call ('member' create), you would want something on the lines of...
{
"email_address":"example#freddiesjokes.com",
"status":"subscribed",
"interests": {
"b8a9d7cbf6": true
},
# ADDITIONAL FIELDS, IF REQUIRED...
"merge_fields":{
"FNAME": "foo bar",
"LNAME": "foo bar",
"MERGE3": "foo bar",
"MERGE4": "foo bar"
}
}
A PUT call ('member' edit) example...
{
"interests": {
"b8a9d7cbf6": false,
"5998e44916": true
}
}
For PUT requests, it seems that you must declare every 'interest' and state whether it is true or false.
I think this is what you are looking for: Lists Interest Categories Collection
In that endpoint you can get and create new groups for lists. And here Lists Interests Collection you can get interests or create new ones.
Lemonades
Coca Cola
Pepsi Max
Fanta
Lemonades represents category or better a group name. Cola, pepsi and fanta represents interests or better group items in that spesific group/category.
Hope this helps :)

MongoDB pagination with grouped item

I am building a messaging module into an existing web app. We are storing the messages in mongo with a data structure that something looks like:
{
id: "",
inResponseToMessageId: ""
to: []
cc: []
bcc: []
subject: ""
body: ""
owners: [{id:4, status:"read", folder:"inbox"}, {id:1, status:'unread', folder:'inbox'}]
dateSent:
}
The client would like us to be able to display messages in both a conversation view and a singleton view.
I am having trouble figuring out an efficient query that can
Return results grouped by message thread.
Work well with pagination.
Sortable by date and subject.
I can modify the data structure however I need in order to get this to work well.
Below are a few possible solutions but they all seem to fall short:
Store messages as children of a thread object.
Add a threadId to each message and then query and group by threadId.
Create some type of meta information object that helps.
The problem with the standard mongo group or $group function is that I imagine it will perform very poorly when the collection is large. We are expecting there to be hundreds of millions of messages in the collection.
Put a threadId on your messages.
Return results grouped by message thread.
You can find messages by thread like
db.messages.find({ "threadId" : id })
I don't think there's any need to group them in the sense of the $group operator.
Work well with pagination.
Pagination for the messages in what order? Pagination works well if you have a sort on a unique field. dateSent should be unique if you keep it to millisecond precision, so you can paginate on it.
// page 1
db.messages.find({ "threadId" : id }).sort({ "dateSent" : -1 }).limit(25)
// page 2
db.messages.find({ "threadId" : id, "dateSent" : { "$gt" : <25th date sent> } }).sort({ "dateSent" : -1 }).limit(25)
Sortable by date and subject.
Who sorts messages by subject? Anyway, this is just a matter of creating the right indexes if you want to retrieve messages in date or subject order. Depending on your requirements you might be doing this sorting for a client view, where it might not be necessary to have the database sort the results. The client could do it for the returned subset instead.

How do I fetch the next page of results, by following the URI

"The SoundCloud API will be dropping support for offset-based pagination on March 2, 2015, in favor of linked partitioning.
To page through a JSON response, pass the linked_partitioning=1 parameter along with your request and it will return a collection, along with a next_href property if there are additional results. To fetch the next page of results, simply follow that URI. If the response does not contain a next_href property, you have reached the end of the results."
I'm trying to do this in ruby with the soundcloud api. I know max results are 200, but if I search through 500 I will literally see "next_href" in the response. Is it possible to continue the search? How do I do it if its possible?
When I try calling it, I end up getting a syntax error ":undefined method `title'" or just not the requested amount of results.
When you request a collection of resources (eg: search results, stream tracks), if you don't get the full collection back again, in the response is a field called next_href. This is a url pointing to the next page of the same collection. Each subsequent page will give you a next_href until you reach the end and none will exist. As an example:
/users/2/tracks.json?limit=10
{
"collection": [ { id: 123, title: ... }, { id: 456 ... }, ... ],
"next_href": "https://api.soundcloud.com/users/2/tracks.json?limit=10&offset=10"
}
I don't quite know what you mean here:
When I try calling it, I end up getting a syntax error ":undefined method `title'" or just not the requested amount of results.
That sounds like a bug in your ruby code.

Grails chained drop down

I'm trying to implement chained drop down boxes using the tutorial here. My classes are not as straight forward as the ones in the tutorial though.
I want to chain the drop down boxes for the create.gsp view in the Load class. Each load belongs to an account from the Account class, and each account belongs to a user from the User class, and each user has several cargo destinations from the Address class.
My goal is to have the cargo destination field up date based on which account is selected.
I am having trouble understanding the AJAX function in the tutorial (step 3), and how it relates to the Grails function (step 4).
Here is the AJAX code:
function respondToSelect(event)
{
new Ajax.Updater("memberSelect",
"/chainedSelect/family/updateSelect",
{method:'get', parameters: {selectedValue : $F("familySelect")} }
);
}
Here is the Grails method:
def updateSelect = {
def familySelected = Family.find("from Family as family where family.surname=:surname", [surname:params.selectedValue])
render (template:"selectMember", model : ['familySelected' : familySelected])
}
If someone could just explain what the third parameter of the AJAX function is doing I think I can figure the Grails part out.
{method:'get', parameters: {selectedValue : $F("account")}}
If someone could just explain what the third parameter of the AJAX
function is doing
The third argument is an object of parameters that get passed to the Updater that tell it how to make the HTTP request to the server.
Make the request an HTTP GET request:
method:'get'
Pass the following named query parameters:
{selectedValue: $F("account")}
$F is a prototype shortcut to retrieve the value of an element. In this case, it's getting the selected value of the DOM element with id account.
This ultimately results in something like the following request:
GET /chainedSelect/family/updateSelect?selectedValue=someValue
Where "someValue" is the currently-selected item in the "account" select list.

Resources